Submit

Back to the channels

#primate

  1. phaleth just dump another 5k commits on top of those 15k pre-existing ones https://github.com/oven-sh/bun/tree/claude/phase-a-port
  2. bot <discord:blue> Lol
  3. bot <discord:blue> phaleth: [primate-run/primate] Pull request opened: #269 core: remove debug client-side console logs
  4. bot <discord:blue> Does this work in ssr?
  5. bot <discord:blue> Ah sorry, wrong pr, stupid phone
  6. bot <discord:blue> [primate-run/primate] Pull request opened: #271 website: reduce network dependency tree to lower latency
  7. bot <discord:blue> Meant this
  8. phaleth yeah, that doesn't change anything server-side, it's a change in .svelte file
  9. bot <discord:blue> Yeah I know
  10. bot <discord:blue> But this is likely to fail in ssr
  11. bot <discord:blue> https://github.com/primate-run/primate/blob/master/apps/website/static/localStorage.ts#L8
  12. phaleth the theme changes just fine, that line of code works
  13. bot <discord:blue> Crazy
  14. phaleth it's just a merge of two JS chunk into a single JS chunk client side
  15. phaleth two JS chunks*
  16. bot <discord:blue> Did you try npx primate build & npx primate serve?
  17. bot <discord:blue> On your comp, I mean
  18. phaleth I will try
  19. bot <discord:blue> Yeah I know, the only reason for that chunk is that localStorage doesn't exist on the global namespace in node
  20. phaleth TypeError: localStorage.getItem is not a function
  21. phaleth at file:///home/user/primate/primate/apps/website/build/server.js:74:2010
  22. bot <discord:blue> Yup
  23. phaleth ok, so can we just not do that server side if it's only to change theme?
  24. phaleth it's weird that it only shows on prod build
  25. bot <discord:blue> Yeah, ssr in inactive in dev
  26. phaleth heh
  27. bot <discord:blue> Due to limitations in node, mostly
  28. bot <discord:blue> We should be able to get it reactivated since deno seems to be making good progress in custom loaders
  29. bot <discord:blue> Dunno about bun thougg
  30. phaleth I mean the theme is stored in localStorage client side, so why bother with it server side anyway?
  31. phaleth it's also detected client side
  32. bot <discord:blue> Yeah I agree, which is why this thing runs in a chunk
  33. bot <discord:blue> There's probably a better way to load it only in the client
  34. phaleth yeah, I think so
  35. bot <discord:blue> We just need to not bundle it in in server code
  36. phaleth you can close that PR, I will try to come up with something else
  37. phaleth so that means I should be able to eliminate two kind of fetch calls at once
  38. phaleth if I figure out how anyway
  39. blue ok, game's on
  40. blue I'll merge the other two things, then look at the third one we just discussed
  41. phaleth ok, cool
  42. phaleth a fork bomb https://images4.imagebam.com/48/03/91/ME1CWZMC_o.png or so
  43. blue 09:23 < phaleth> just dump another 5k commits on top of those 15k pre-existing ones https://github.com/oven-sh/bun/tree/claude/phase-a-port
  44. blue sumner losing his mind again and running a friggin hype train
  45. blue gosh this guy gets on my nerves
  46. blue what is this exe, phaleth?
  47. blue I figure we need some kind of localStorage in rcompat, phaleth
  48. blue that offers setItem and getItem, and does absolutely nothing
  49. blue the real way would be to not bundle this code at all on the server
  50. blue I mean, localStorage.ts
  51. blue but that's the point of the chunk
  52. blue diff question, can we force esbuild to dechunk?
  53. blue that would be awesome
  54. phaleth those exes are the kernel isolation thingies
  55. blue what kernel isolation
  56. phaleth the ones spawned by gvisor
  57. blue oh
  58. blue that's terribly expensive ramwise, no?
  59. blue so one of our options is "splitting: false" on the client
  60. blue I personally never got the real point of chunking anyway so I'm inclined to consider this
  61. phaleth blue: here are the new instructions on how to update primate website https://gitea.repopack.app/repopack/provision/src/branch/master/podman/deployments/primate-site.md#how-to-update-primate-website
  62. blue can you try this in your PR, phaleth?
  63. blue go to packages/core/src/private/build/client/index.ts
  64. blue change line 105 to false
  65. blue then undo your change (put the import back in as a dynamic import)
  66. blue and run npx primate build && npx primate serve
  67. blue 1) does it build
  68. blue and 2) does it dechunk?
  69. phaleth yeah, but that means the first chunk won't be there and so overall hydration will become slower
  70. phaleth take a look at the picture on the PR
  71. blue how do? there is the base bundle + the localStorage chunk
  72. blue splitting: false will merge the localStorage chunk onto the base bundle
  73. blue how so*
  74. blue so effectively chunk-L5MXQA3Q will disappear
  75. blue you'll only have app.js
  76. blue also don't forget to rebuild @primate/core
  77. phaleth yeah, I know, but that chunk is big so it better stay chunked
  78. blue `npm run build` in packages/core, should be fast now with tsgo
  79. phaleth otherwise the site will hydrate slower
  80. phaleth I hope the app-whatever.js chunk is holding all the click events
  81. blue I have no idea why that chunk is so big. svelte/store is 18KiB???
  82. phaleth I just ran npm run build million times in last three ours, it's fast
  83. blue anyway, if you're concerned about size, then your PR would be moot anyway
  84. blue I'd get rid of the splitting anyway
  85. phaleth no, don't worry
  86. blue that being said, svelte's wirable store pulling in 18 kilobytes of stuff is totally unacceptable
  87. blue don't you agree?
  88. phaleth well if you can make the chunk-whatever.js smaller then sure I agree
  89. phaleth if you can make any JS smaller then that'd be great
  90. blue well technically speaking, stores in svelte are a very dumbed down contract
  91. blue essentially { subscribe() } is a store, iirc
  92. phaleth can just use props instead of store I think, just need to be bothered to pass them around
  93. blue I'm just surprised this is 18K
  94. phaleth it's like react's context I think
  95. phaleth all it boils down to is global JS vars
  96. blue so I asked the mind hive, and it came up with this
  97. blue "When esbuild splits that dynamic import into its own chunk, it has to make the chunk self-contained, so it bundles everything that chunk needs — including the Svelte runtime internals that writable depends on. In your main bundle, that runtime is already there, but the chunk can't assume that, so it duplicates it."
  98. blue "This is the classic chunk duplication problem with code splitting. The chunk doesn't know what's already loaded in the parent bundle."
  99. blue that's fair and I'm inclined to believe the clanker here
  100. blue so could you try what I suggested? I'm betting the combined size won't be significantly larger -- localStorage.ts is roundabout 685 bytes
  101. phaleth ok, give me a few
  102. blue if what the clanker said is true, this is dumb on more than one level -- we don't wanna serve the svelte runtime twice
  103. blue best case scenario we save 17KB + the extra HTTP request
  104. blue oh right, it's 685 bytes un=minified. I bet we're talking about much less later
  105. blue unminified*
  106. blue beyond that, it's questionable design by svelte that writable depends on the svelte runtime, but ok
  107. blue I kinda get it, they wanna reuse their signal code or whatever they call it internally. still feels bit much for a signal lib, 17KB. maybe I'm overly optimistic here
  108. phaleth it's questionable that the chunk is standalone
  109. blue yeah, it's a solution looking for a problem, agreed
  110. blue as said I never really got chunking per se, another complexity that webpack brought into the world
  111. phaleth ok, in case of primate website the performance is better when chunks are not split https://images4.imagebam.com/0c/7c/66/ME1CX1XJ_o.png
  112. phaleth but for a bigger web app that might not be the case
  113. phaleth also the JS amount adds up, so clanker was wrong
  114. phaleth or the bundler is just dumb
  115. phaleth I suppose I should try to get rid of both of those dynamic imports
  116. blue so we want from
  117. blue 2 requests, 29.5 + 17.88 KiB
  118. blue to 1 request, 46.93 KiB?
  119. blue the combined is 47.38 KiB
  120. blue clanker made up nonsense, again
  121. blue we went*
  122. phaleth yeah, chunks are not standalone
  123. blue anyway, turn off splitting
  124. phaleth no, that's not the point
  125. phaleth :D
  126. blue so what's the point, you want a conf option to turn off splitting?
  127. blue what's the other dynamic import?
  128. phaleth is the first chunking done somewhere as part of the website code? or is that primate feature?
  129. phaleth from app-whatever.js to chunk-whatever.js
  130. phaleth cause I think if I manage to undo that chunking then the ssr or whatever will be happy
  131. blue so what you just sent got rid of boht chunks, right? or rather of the one chunk and its depndency?
  132. blue as far as I know this is the only chunk
  133. phaleth in that PR I've only managed to remove the leaf chunk
  134. phaleth the mid chunk is still there, at least in the code
  135. phaleth and my question is where in the code?
  136. blue that's weird, that shouldn't be the case
  137. blue so it works like this
  138. blue you have components/Header.svelte
  139. blue this does a dynamic import
  140. blue esbuild sees that, creates a chunk
  141. blue I don't specifically know or understand *why* that chunk then issues another request to specifically load localStorage.ts, it shouldn't
  142. phaleth uh
  143. phaleth hmm, I think Header.svelte is part of app-whatever.js in any case
  144. blue it is, yes
  145. blue and esbuild rewrites it to use `fetch` instead of that import
  146. phaleth let me see if chunk-whatever.js is still created after that PR is applied
  147. blue k
  148. phaleth ok, you are right, it's single app.js now
  149. blue yes
  150. phaleth that's great
  151. blue as it should be
  152. phaleth so I gotta get rid of the server side magic
  153. blue what server side magic
  154. phaleth the ssr thing that errors
  155. phaleth due to not getting localStorage or whatever
  156. phaleth TypeError: localStorage.getItem is not a function
  157. phaleth at file:///home/user/primate/primate/apps/website/build/server.js:74:2010
  158. blue you don't need to, do you?
  159. blue you keep the await import in Header.svelte
  160. blue then you piggy back on the fact that svelte's `onMount` is a no-op in SSR
  161. blue so esbuild won't see the dynamic import in the server bundle
  162. phaleth I do need to get rid of that dynamic import
  163. blue why?
  164. blue the bundle size is the same, no?
  165. phaleth that's what I'm going to find out
  166. phaleth I can at least make it smaller by getting rid of some of this glue code
  167. blue so I frankly don't understand what svelte/store is pulling in that justifies 17kb
  168. phaleth what I don't know how does localStorage instance appear out of nowhere in #static/localStorage.ts
  169. blue this is because this is a browser file, and on the browser, localStorage is global
  170. phaleth oh, true
  171. blue you can also write globalThis.localStorage if that makes you feel better
  172. phaleth it does
  173. blue good, then do it
  174. blue magical stuff is bad bananas
  175. blue let me add that to the list of carnal sins in CS
  176. blue so what have we got
  177. blue caching, complexity, and magic?
  178. phaleth it's a TS error
  179. blue what's a TS error
  180. blue oh right
  181. blue yeah, TS doesn't understand you're in a browser file
  182. blue luckily, you can ignore that
  183. blue or if that bothers you, add `@ts-expect-error browser context` or so
  184. phaleth can I do @ts-ignore?
  185. blue above that line
  186. blue yes
  187. phaleth oh, ok
  188. blue this is a problem in and of itself. there is no good way to teach TS in what context your JS file in
  189. blue I think react has something like "use:client" but that's terrible
  190. blue TS *could* benefit from taking a look at package.json runtime keys and figuring it out based on the "browser" import, but I doubt it does that, I doubt there is political will in microsoft to do that, and also that would bring you nothing in this case because localStorage isn't declared in apps/website's package.json
  191. blue I also somewhat have a convention in primate where browser files are extension'd `*.client.ts`
  192. blue but this is purely a convention with no consequence, I cannot guarantee I have followed it everywhere, and also I don't know and couldn't bother to look up how to teach nvim to understand that that is a browser TS file
  193. blue and given I've criticised myself the fact that svelte 5 magically treats *.svelte.js files differently than normal *.js files, I shouldn't do the same thing myself
  194. blue you know, the problem with all those frontends is that they legit try to do too much. svelte does this rune magic, but it only really works if you use it the blessed path, which is either sveltekit or vite
  195. blue that's terribly proprietary and vendor-lock-in-y
  196. blue it's not how software is supposed to be
  197. blue I feel like the modern shift has been, everything is open source, but tools are *so* locked to just one path that they're effectively proprietary
  198. blue do you want to bundle in the woff2 font as well? :P
  199. blue probably not, you're precaching it and stuff
  200. phaleth nope, still didn't figure out how to add Content-Length header to JS
  201. phaleth those frontend frameworks are the problem
  202. blue 100%
  203. phaleth what I don't understand is that how does #static/localStorage.ts end up being in a server side bundle server.js?
  204. phaleth I think I'll just move it's code to Header.svelte and see
  205. phaleth oh, that worked
  206. phaleth so yeah, don't add TS code to static dir
  207. phaleth actually, getting a new error now
  208. phaleth [ERROR] views/Index.svelte error: TypeError: localStorage.getItem is not a function
  209. blue that's the same SSR dir
  210. blue SSR error*
  211. blue I do have a solution for you
  212. blue colorscheme = (await import("#static/localStorage.ts")).default;
  213. blue move this to a top-level import, as you did in your PR
  214. blue you can move localStorage to components or whatever you like, it doesn't really matter
  215. blue anyway, create localStorage.client.ts
  216. blue put the code from localStorage.ts in it
  217. blue and in localStorage.ts, do something like `export default {}`
  218. phaleth to which dir should I put localStorage.client.ts? view?
  219. blue where you like. best in the same dir as localStorage.ts
  220. blue if you wanna keep it in static put it there. otherwise move both to components
  221. blue components is ok I tihnk
  222. blue and the last piece of hte puzzle, add runtime keys for both files
  223. blue in package.json, add
  224. blue https://dpaste.com/7JV3D2SJ8
  225. blue and make sure the import is like that
  226. blue import localStorage from "#localStorage";
  227. phaleth I cannot open dpaste cause of proxy
  228. blue https://superarch.org/ls.txt
  229. phaleth wth
  230. phaleth it works :D
  231. phaleth magic replaces magic
  232. blue yes. though this is magic per se: we're explicitly telling esbuild how to bundle it for the browser and server
  233. blue this isn't*
  234. blue anyway, this is the 'right' solution: because it means the code doesn't get bundled in to the server
  235. phaleth ok, I'm gonna update the PR
  236. blue great
  237. phaleth looks like Angular
  238. phaleth so there is about 6 kBs of JS less on the frontend, which is great
  239. blue that's awesome
  240. blue oh sweet, you delegated to svelte store on the server, that's smart
  241. phaleth yeah, well, that just means there is more work to do
  242. phaleth anyway, the network dependency graph problem is solved
  243. blue good job
  244. blue phaleth: the pr is merged
  245. phaleth cool, can you try updating the website using those new instructions?
  246. phaleth don't have to strictly follow that, can as well update all of those packages that the website uses
  247. blue phaleth: I usally just go into the contain and git pull and rebuild
  248. blue container*
  249. phaleth yeah, but it's a podman container now
  250. phaleth I've rebuilt the image so the website is updated
  251. bot <discord:blue> Great
  252. bot <discord:blue> So it's better now?
  253. phaleth yes, gets a higher score on https://pagespeed.web.dev
  254. bot <discord:blue> Performance, 100
  255. bot <discord:blue> Great

Search posts