Chat Logs

  1. * phaleth joined #primate
  2. phalethjust 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. phalethyeah, 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. phaleththe theme changes just fine, that line of code works
  14. bot<discord:blue> Crazy
  15. phalethit's just a merge of two JS chunk into a single JS chunk client side
  16. phalethtwo 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. phalethI 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. phalethTypeError: 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. phalethok, so can we just not do that server side if it's only to change theme?
  25. phalethit's weird that it only shows on prod build
  26. bot<discord:blue> Yeah, ssr in inactive in dev
  27. phalethheh
  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. phalethI mean the theme is stored in localStorage client side, so why bother with it server side anyway?
  32. phalethit'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. phalethyeah, I think so
  36. bot<discord:blue> We just need to not bundle it in in server code
  37. phalethyou can close that PR, I will try to come up with something else
  38. phalethso that means I should be able to eliminate two kind of fetch calls at once
  39. phalethif I figure out how anyway
  40. blueok, game's on
  41. blueI'll merge the other two things, then look at the third one we just discussed
  42. phalethok, cool
  43. phaletha fork bomb https://images4.imagebam.com/48/03/91/ME1CWZMC_o.png or so
  44. blue09: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. bluesumner losing his mind again and running a friggin hype train
  46. bluegosh this guy gets on my nerves
  47. bluewhat is this exe, phaleth?
  48. blueI figure we need some kind of localStorage in rcompat, phaleth
  49. bluethat offers setItem and getItem, and does absolutely nothing
  50. bluethe real way would be to not bundle this code at all on the server
  51. blueI mean, localStorage.ts
  52. bluebut that's the point of the chunk
  53. bluediff question, can we force esbuild to dechunk?
  54. bluethat would be awesome
  55. phaleththose exes are the kernel isolation thingies
  56. bluewhat kernel isolation
  57. phaleththe ones spawned by gvisor
  58. blueoh
  59. bluethat's terribly expensive ramwise, no?
  60. blueso one of our options is "splitting: false" on the client
  61. blueI personally never got the real point of chunking anyway so I'm inclined to consider this
  62. phalethblue: 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. bluecan you try this in your PR, phaleth?
  64. bluego to packages/core/src/private/build/client/index.ts
  65. bluechange line 105 to false
  66. bluethen undo your change (put the import back in as a dynamic import)
  67. blueand run npx primate build && npx primate serve
  68. blue1) does it build
  69. blueand 2) does it dechunk?
  70. phalethyeah, but that means the first chunk won't be there and so overall hydration will become slower
  71. phalethtake a look at the picture on the PR
  72. bluehow do? there is the base bundle + the localStorage chunk
  73. bluesplitting: false will merge the localStorage chunk onto the base bundle
  74. bluehow so*
  75. blueso effectively chunk-L5MXQA3Q will disappear
  76. blueyou'll only have app.js
  77. bluealso don't forget to rebuild @primate/core
  78. phalethyeah, 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. phalethotherwise the site will hydrate slower
  81. phalethI hope the app-whatever.js chunk is holding all the click events
  82. blueI have no idea why that chunk is so big. svelte/store is 18KiB???
  83. phalethI just ran npm run build million times in last three ours, it's fast
  84. blueanyway, if you're concerned about size, then your PR would be moot anyway
  85. blueI'd get rid of the splitting anyway
  86. phalethno, don't worry
  87. bluethat being said, svelte's wirable store pulling in 18 kilobytes of stuff is totally unacceptable
  88. bluedon't you agree?
  89. phalethwell if you can make the chunk-whatever.js smaller then sure I agree
  90. phalethif you can make any JS smaller then that'd be great
  91. bluewell technically speaking, stores in svelte are a very dumbed down contract
  92. blueessentially { subscribe() } is a store, iirc
  93. phalethcan just use props instead of store I think, just need to be bothered to pass them around
  94. blueI'm just surprised this is 18K
  95. phalethit's like react's context I think
  96. phalethall it boils down to is global JS vars
  97. blueso 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. bluethat's fair and I'm inclined to believe the clanker here
  101. blueso could you try what I suggested? I'm betting the combined size won't be significantly larger -- localStorage.ts is roundabout 685 bytes
  102. phalethok, give me a few
  103. blueif what the clanker said is true, this is dumb on more than one level -- we don't wanna serve the svelte runtime twice
  104. bluebest case scenario we save 17KB + the extra HTTP request
  105. blueoh right, it's 685 bytes un=minified. I bet we're talking about much less later
  106. blueunminified*
  107. bluebeyond that, it's questionable design by svelte that writable depends on the svelte runtime, but ok
  108. blueI 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. phalethit's questionable that the chunk is standalone
  110. blueyeah, it's a solution looking for a problem, agreed
  111. blueas said I never really got chunking per se, another complexity that webpack brought into the world
  112. phalethok, 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. phalethbut for a bigger web app that might not be the case
  114. phalethalso the JS amount adds up, so clanker was wrong
  115. phalethor the bundler is just dumb
  116. phalethI suppose I should try to get rid of both of those dynamic imports
  117. blueso we want from
  118. blue2 requests, 29.5 + 17.88 KiB
  119. blueto 1 request, 46.93 KiB?
  120. bluethe combined is 47.38 KiB
  121. blueclanker made up nonsense, again
  122. bluewe went*
  123. phalethyeah, chunks are not standalone
  124. blueanyway, turn off splitting
  125. phalethno, that's not the point
  126. phaleth:D
  127. blueso what's the point, you want a conf option to turn off splitting?
  128. bluewhat's the other dynamic import?
  129. phalethis the first chunking done somewhere as part of the website code? or is that primate feature?
  130. phalethfrom app-whatever.js to chunk-whatever.js
  131. phalethcause I think if I manage to undo that chunking then the ssr or whatever will be happy
  132. blueso what you just sent got rid of boht chunks, right? or rather of the one chunk and its depndency?
  133. blueas far as I know this is the only chunk
  134. phalethin that PR I've only managed to remove the leaf chunk
  135. phaleththe mid chunk is still there, at least in the code
  136. phalethand my question is where in the code?
  137. bluethat's weird, that shouldn't be the case
  138. blueso it works like this
  139. blueyou have components/Header.svelte
  140. bluethis does a dynamic import
  141. blueesbuild sees that, creates a chunk
  142. blueI don't specifically know or understand *why* that chunk then issues another request to specifically load localStorage.ts, it shouldn't
  143. phalethuh
  144. phalethhmm, I think Header.svelte is part of app-whatever.js in any case
  145. blueit is, yes
  146. blueand esbuild rewrites it to use `fetch` instead of that import
  147. phalethlet me see if chunk-whatever.js is still created after that PR is applied
  148. bluek
  149. phalethok, you are right, it's single app.js now
  150. blueyes
  151. phaleththat's great
  152. blueas it should be
  153. phalethso I gotta get rid of the server side magic
  154. bluewhat server side magic
  155. phaleththe ssr thing that errors
  156. phalethdue to not getting localStorage or whatever
  157. phalethTypeError: localStorage.getItem is not a function
  158. phaleth at file:///home/user/primate/primate/apps/website/build/server.js:74:2010
  159. blueyou don't need to, do you?
  160. blueyou keep the await import in Header.svelte
  161. bluethen you piggy back on the fact that svelte's `onMount` is a no-op in SSR
  162. blueso esbuild won't see the dynamic import in the server bundle
  163. phalethI do need to get rid of that dynamic import
  164. bluewhy?
  165. bluethe bundle size is the same, no?
  166. phaleththat's what I'm going to find out
  167. phalethI can at least make it smaller by getting rid of some of this glue code
  168. blueso I frankly don't understand what svelte/store is pulling in that justifies 17kb
  169. phalethwhat I don't know how does localStorage instance appear out of nowhere in #static/localStorage.ts
  170. bluethis is because this is a browser file, and on the browser, localStorage is global
  171. phalethoh, true
  172. blueyou can also write globalThis.localStorage if that makes you feel better
  173. phalethit does
  174. bluegood, then do it
  175. bluemagical stuff is bad bananas
  176. bluelet me add that to the list of carnal sins in CS
  177. blueso what have we got
  178. bluecaching, complexity, and magic?
  179. phalethit's a TS error
  180. bluewhat's a TS error
  181. blueoh right
  182. blueyeah, TS doesn't understand you're in a browser file
  183. blueluckily, you can ignore that
  184. blueor if that bothers you, add `@ts-expect-error browser context` or so
  185. phalethcan I do @ts-ignore?
  186. blueabove that line
  187. blueyes
  188. phalethoh, ok
  189. bluethis is a problem in and of itself. there is no good way to teach TS in what context your JS file in
  190. blueI think react has something like "use:client" but that's terrible
  191. blueTS *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. blueI also somewhat have a convention in primate where browser files are extension'd `*.client.ts`
  193. bluebut 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. blueand 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. blueyou 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. bluethat's terribly proprietary and vendor-lock-in-y
  197. blueit's not how software is supposed to be
  198. blueI 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. bluedo you want to bundle in the woff2 font as well? :P
  200. blueprobably not, you're precaching it and stuff
  201. phalethnope, still didn't figure out how to add Content-Length header to JS
  202. phaleththose frontend frameworks are the problem
  203. blue100%
  204. phalethwhat I don't understand is that how does #static/localStorage.ts end up being in a server side bundle server.js?
  205. phalethI think I'll just move it's code to Header.svelte and see
  206. phalethoh, that worked
  207. phalethso yeah, don't add TS code to static dir
  208. phalethactually, getting a new error now
  209. phaleth[ERROR] views/Index.svelte error: TypeError: localStorage.getItem is not a function
  210. bluethat's the same SSR dir
  211. blueSSR error*
  212. blueI do have a solution for you
  213. blue colorscheme = (await import("#static/localStorage.ts")).default;
  214. bluemove this to a top-level import, as you did in your PR
  215. blueyou can move localStorage to components or whatever you like, it doesn't really matter
  216. blueanyway, create localStorage.client.ts
  217. blueput the code from localStorage.ts in it
  218. blueand in localStorage.ts, do something like `export default {}`
  219. phalethto which dir should I put localStorage.client.ts? view?
  220. bluewhere you like. best in the same dir as localStorage.ts
  221. blueif you wanna keep it in static put it there. otherwise move both to components
  222. bluecomponents is ok I tihnk
  223. blueand the last piece of hte puzzle, add runtime keys for both files
  224. bluein package.json, add
  225. bluehttps://dpaste.com/7JV3D2SJ8
  226. blueand make sure the import is like that
  227. blueimport localStorage from "#localStorage";
  228. phalethI cannot open dpaste cause of proxy
  229. bluehttps://superarch.org/ls.txt
  230. phalethwth
  231. phalethit works :D
  232. phalethmagic replaces magic
  233. blueyes. though this is magic per se: we're explicitly telling esbuild how to bundle it for the browser and server
  234. bluethis isn't*
  235. blueanyway, this is the 'right' solution: because it means the code doesn't get bundled in to the server
  236. phalethok, I'm gonna update the PR
  237. bluegreat
  238. phalethlooks like Angular
  239. phalethso there is about 6 kBs of JS less on the frontend, which is great
  240. bluethat's awesome
  241. blueoh sweet, you delegated to svelte store on the server, that's smart
  242. phalethyeah, well, that just means there is more work to do
  243. phalethanyway, the network dependency graph problem is solved
  244. bluegood job
  245. bluephaleth: the pr is merged
  246. phalethcool, can you try updating the website using those new instructions?
  247. phalethdon't have to strictly follow that, can as well update all of those packages that the website uses
  248. bluephaleth: I usally just go into the contain and git pull and rebuild
  249. bluecontainer*
  250. phalethyeah, but it's a podman container now
  251. phalethI've rebuilt the image so the website is updated
  252. bot<discord:blue> Great
  253. bot<discord:blue> So it's better now?
  254. phalethyes, gets a higher score on https://pagespeed.web.dev
  255. bot<discord:blue> Performance, 100
  256. bot<discord:blue> Great