Using createAsync in SolidJS: Handling Data Dependencies
Currently, I'm thinking of two approaches:
Unified Loader Pattern:
Separate Async Queries Pattern (commented out):
My key questions are:
Data Loading Strategy
Is it better to use a unified loader that fetches all related data in one query (similar to Remix's loader pattern), or should we use separate createAsync calls for each data dependency?
Dynamic Data Updates
How should we handle dynamic updates when a program is selected? Currently, the form has this select handler:
But changing the program doesn't update the variants because they're loaded once through the unified loader.
Dependency Management
The
variants
depend on the selected programId
. The current loader handles this initial dependency well, but doesn't account for dynamic updates.
Potential solutions:
- Keep the loader for initial data but add a separate action/query for variant updates
- Return to separate createAsync calls with proper dependency tracking
- Implement a hybrid approach
What's the most idiomatic way to handle this in SolidJS, considering both initial load and dynamic updates?3 Replies
This is what I have after several iteration:
The main point is:
And using an action to retrieve the data via useSubmission, but this seems convoluted..
The problem with a unified loader is that you are creating unnecessary waterfalls.
In your example the
programm query
does not depend on anything but the query only gets called after criterion
has resolved and then it blocks the variant query
.
With seperate queries each with createAsync those queries run all in parallel. => faster TTFB.
Another benefit is that createAsync
tracks dependencies. So setting programmId
causes getCriterion
to refetch with the new ID.
But then you have to be aware that the variants query might run with programmId when it's still undefined so you might want to guard against that like
For preloading solid-start and the router provide the preload option where you'd just call the functionis this a pattern to return early from an action like that? this could indeed solve my problem.. i'll try this tomorrow and see how the network tab behave !