bluego to packages/core/src/private/build/client/index.ts
bluechange line 105 to false
bluethen undo your change (put the import back in as a dynamic import)
blueand run npx primate build && npx primate serve
blue1) does it build
blueand 2) does it dechunk?
phalethyeah, but that means the first chunk won't be there and so overall hydration will become slower
phalethtake a look at the picture on the PR
bluehow do? there is the base bundle + the localStorage chunk
bluesplitting: false will merge the localStorage chunk onto the base bundle
bluehow so*
blueso effectively chunk-L5MXQA3Q will disappear
blueyou'll only have app.js
bluealso don't forget to rebuild @primate/core
phalethyeah, I know, but that chunk is big so it better stay chunked
blue`npm run build` in packages/core, should be fast now with tsgo
phalethotherwise the site will hydrate slower
phalethI hope the app-whatever.js chunk is holding all the click events
blueI have no idea why that chunk is so big. svelte/store is 18KiB???
phalethI just ran npm run build million times in last three ours, it's fast
blueanyway, if you're concerned about size, then your PR would be moot anyway
blueI'd get rid of the splitting anyway
phalethno, don't worry
bluethat being said, svelte's wirable store pulling in 18 kilobytes of stuff is totally unacceptable
bluedon't you agree?
phalethwell if you can make the chunk-whatever.js smaller then sure I agree
phalethif you can make any JS smaller then that'd be great
bluewell technically speaking, stores in svelte are a very dumbed down contract
blueessentially { subscribe() } is a store, iirc
phalethcan just use props instead of store I think, just need to be bothered to pass them around
blueI'm just surprised this is 18K
phalethit's like react's context I think
phalethall it boils down to is global JS vars
blueso I asked the mind hive, and it came up with this
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."
blue"This is the classic chunk duplication problem with code splitting. The chunk doesn't know what's already loaded in the parent bundle."
bluethat's fair and I'm inclined to believe the clanker here
blueso could you try what I suggested? I'm betting the combined size won't be significantly larger -- localStorage.ts is roundabout 685 bytes
phalethok, give me a few
blueif what the clanker said is true, this is dumb on more than one level -- we don't wanna serve the svelte runtime twice
bluebest case scenario we save 17KB + the extra HTTP request
blueoh right, it's 685 bytes un=minified. I bet we're talking about much less later
blueunminified*
bluebeyond that, it's questionable design by svelte that writable depends on the svelte runtime, but ok
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
phalethit's questionable that the chunk is standalone
blueyeah, it's a solution looking for a problem, agreed
blueas said I never really got chunking per se, another complexity that webpack brought into the world
phalethbut for a bigger web app that might not be the case
phalethalso the JS amount adds up, so clanker was wrong
phalethor the bundler is just dumb
phalethI suppose I should try to get rid of both of those dynamic imports
blueso we want from
blue2 requests, 29.5 + 17.88 KiB
blueto 1 request, 46.93 KiB?
bluethe combined is 47.38 KiB
blueclanker made up nonsense, again
bluewe went*
phalethyeah, chunks are not standalone
blueanyway, turn off splitting
phalethno, that's not the point
phaleth:D
blueso what's the point, you want a conf option to turn off splitting?
bluewhat's the other dynamic import?
phalethis the first chunking done somewhere as part of the website code? or is that primate feature?
phalethfrom app-whatever.js to chunk-whatever.js
phalethcause I think if I manage to undo that chunking then the ssr or whatever will be happy
blueso what you just sent got rid of boht chunks, right? or rather of the one chunk and its depndency?
blueas far as I know this is the only chunk
phalethin that PR I've only managed to remove the leaf chunk
phaleththe mid chunk is still there, at least in the code
phalethand my question is where in the code?
bluethat's weird, that shouldn't be the case
blueso it works like this
blueyou have components/Header.svelte
bluethis does a dynamic import
blueesbuild sees that, creates a chunk
blueI don't specifically know or understand *why* that chunk then issues another request to specifically load localStorage.ts, it shouldn't
phalethuh
phalethhmm, I think Header.svelte is part of app-whatever.js in any case
blueit is, yes
blueand esbuild rewrites it to use `fetch` instead of that import
phalethlet me see if chunk-whatever.js is still created after that PR is applied
bluek
phalethok, you are right, it's single app.js now
blueyes
phaleththat's great
blueas it should be
phalethso I gotta get rid of the server side magic
bluewhat server side magic
phaleththe ssr thing that errors
phalethdue to not getting localStorage or whatever
phalethTypeError: localStorage.getItem is not a function
phaleth at file:///home/user/primate/primate/apps/website/build/server.js:74:2010
blueyou don't need to, do you?
blueyou keep the await import in Header.svelte
bluethen you piggy back on the fact that svelte's `onMount` is a no-op in SSR
blueso esbuild won't see the dynamic import in the server bundle
phalethI do need to get rid of that dynamic import
bluewhy?
bluethe bundle size is the same, no?
phaleththat's what I'm going to find out
phalethI can at least make it smaller by getting rid of some of this glue code
blueso I frankly don't understand what svelte/store is pulling in that justifies 17kb
phalethwhat I don't know how does localStorage instance appear out of nowhere in #static/localStorage.ts
bluethis is because this is a browser file, and on the browser, localStorage is global
phalethoh, true
blueyou can also write globalThis.localStorage if that makes you feel better
phalethit does
bluegood, then do it
bluemagical stuff is bad bananas
bluelet me add that to the list of carnal sins in CS
blueso what have we got
bluecaching, complexity, and magic?
phalethit's a TS error
bluewhat's a TS error
blueoh right
blueyeah, TS doesn't understand you're in a browser file
blueluckily, you can ignore that
blueor if that bothers you, add `@ts-expect-error browser context` or so
phalethcan I do @ts-ignore?
blueabove that line
blueyes
phalethoh, ok
bluethis is a problem in and of itself. there is no good way to teach TS in what context your JS file in
blueI think react has something like "use:client" but that's terrible
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
blueI also somewhat have a convention in primate where browser files are extension'd `*.client.ts`
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
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
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
bluethat's terribly proprietary and vendor-lock-in-y
blueit's not how software is supposed to be
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
bluedo you want to bundle in the woff2 font as well? :P
blueprobably not, you're precaching it and stuff
phalethnope, still didn't figure out how to add Content-Length header to JS
phaleththose frontend frameworks are the problem
blue100%
phalethwhat I don't understand is that how does #static/localStorage.ts end up being in a server side bundle server.js?
phalethI think I'll just move it's code to Header.svelte and see
phalethoh, that worked
phalethso yeah, don't add TS code to static dir
phalethactually, getting a new error now
phaleth[ERROR] views/Index.svelte error: TypeError: localStorage.getItem is not a function
bluethat's the same SSR dir
blueSSR error*
blueI do have a solution for you
blue colorscheme = (await import("#static/localStorage.ts")).default;
bluemove this to a top-level import, as you did in your PR
blueyou can move localStorage to components or whatever you like, it doesn't really matter
blueanyway, create localStorage.client.ts
blueput the code from localStorage.ts in it
blueand in localStorage.ts, do something like `export default {}`
phalethto which dir should I put localStorage.client.ts? view?
bluewhere you like. best in the same dir as localStorage.ts
blueif you wanna keep it in static put it there. otherwise move both to components
bluecomponents is ok I tihnk
blueand the last piece of hte puzzle, add runtime keys for both files