andi
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
Capture events from child of Portal
i think what's happening is that using this form of listener
oncapture:pointerdown
is hooking directly into the html listener, and since the button is not a child of that element the event doesn't bubble up
if you were to use onPointerDown
it'd work because solid is doing extra work to bubble up the event to parent components too not just DOM parents
but i guess you need the captured pointer down event for a reason
why not add the listener on the button directly?7 replies
Global store in Solid Start app
so in a server context, there is only one instance of the solid library managing things, just like there's only one instance running for a client on a webpage
if you think of solid like a container, all requests from different clients go in the same container
that means that any global state you have will be shared between all clients, which you generally don't want to do because each user should only have access and modify to their own data
the solution to that is to put your global state in a place where it gets created separately for each different request
the recommended way to do it in solid-start would be to create a new store somewhere inside the
root.tsx
component, and passing it to children with a context provider
if you do it like that, you can't import the state directly anymore, you have to use a useContext
hook2 replies
Unable to find modules
seems to me like the import alias
@
is not set up to point to the root of your project
if you're not getting any errors in your editor then typescript is probably set up properly
you can either use this to sync your vite paths to the typescript.json file:
https://www.npmjs.com/package/vite-tsconfig-paths
or do it yourself with adding something like this to your vite.config.ts
:
3 replies
How to allow updating of elements instead of destroying and rendering the elements?
for a different idea from what has been mentioned:
you could use a virtual scrolling/ list component
the gist of it is that it only renders the elements that are in the viewport
https://github.com/minht11/solid-virtual-container
61 replies