Submit

Back to the channels

#primate

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

Search posts