andi
TypeError: Cannot read properties of undefined (reading 'when')
no, it's a pretty big app and the example I posted just now was actually happening across many files and components
if I have time i'll try to dig deeper into the built code, but as I was debugging from the stack trace in the compiled output, I didn't see anything weird going on
18 replies
TypeError: Cannot read properties of undefined (reading 'when')
the global suspense would make the switch component fail with that error
i'm thinking it's a race condition of sorts because it didn't happen 100% of the time, maybe like 70/80%
18 replies
TypeError: Cannot read properties of undefined (reading 'when')
if anyone else runs into something like this, it was caused by a resource somewhere else on the page that was triggering a suspense boundary that would hide the component containing the Switch
it's still not clear why it was happening, almost seemed like a race condition in the rendering causing the bug, but putting a suspense boundary around the resource component stopped the Switch from being hidden and that prevented the bug
18 replies
Good pattern for refetching the data
So for resources, you can optionally pass 2 arguments instead of one, the second one is the fetching function you have, and the first one can be a function returning a value
usually it's an accessor function that would trigger refetches in the resource
if that first function returns a falsy value, then the resource won't trigger a fetch
so basically if you had something like this:
then the resource wouldn't fetch initially because the enabled signal is false
if you later do
setEnabled(true)
it'll trigger an initial fetch
So to answer your original question, you can still extract the resource higher in the component tree, and then only set enabled to true when you want it to fetch initially, for example from the onMount
call of one of the children3 replies
Cache dom elements with router
i think there's other strategies you might want to explore before going down the route of caching the element
like only rendering the part of the component that is in view at first via virtualisation
but maybe someone else with more experience with the router can chime in later
7 replies
Loading screen for app
you could explore other options too
like reducing the whole bundle size, maybe review your dependencies and reimplement the ones that are too big with code that works just for your app
usually generic libraries have a lot of extra code to handle things that you might not ever run into in your app
14 replies
Loading screen for app
so if you split them into two packages, anything that you use from the second chunk would come from an import, something like
import {something} from "second-package"
this is the part that's hard, but if you structure your app in such a way that any functionality coming from the second package you import like this:
and you only trigger those imports when you actually want the second chunk to be fetched, i think it might work
you could probaly set up an experiment manually, with some js files you create yourself by hand with some simple functions and see if you can make the second one only be fethched when you click a button or run a function from the browser console14 replies
Loading screen for app
this depends a lot on how your app is structured but for an idea that might point you into the right direction
split your codebase into 2 packages, and use the manualChunks rollup option in vite to create 2 chunks for your app based on the 2 packages (https://vitejs.dev/guide/build.html#chunking-strategy)
make sure that the second chunk is dynamically imported only when it's needed
you might run into many issues though depending on what you need to set up in the second chunk, global stuff like routes and such will probably have to stay in the initial chunk
14 replies