RFC: serialization of route loaders data #227
Varixo
started this conversation in
Proposals For Qwik
Replies: 1 comment 2 replies
-
Would it affect the "prefetching" strategy? If the data is lazy loaded, it will introduce an extra delay visible to the user while the data is fetched, which will affect negatively the user experience. It would have to be tested/benchmarked, but my feeling is that the extra time it takes to serialize data that is unused is less affecting the UX than a whole new server call (extra delays on user interaction) to fetch the data when needed. Also, should it be the other way around? By default it's serialized (like it is right now) when we can make sure data won't be needed, but you can pass an option (e.g. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What is it about?
Reducing the size of the initial rendered HTML, by being smarter at which data to serialize from the route loaders.
What's the motivation for this proposal?
Problems you are trying to solve:
Let's say we have the following route loader:
Currently we are able to tree shake (or "Data Shake" ™) route loaders data in some simple cases, for example if only a portion of that data is being used.
Example:
But when the component has a condition which affects its rendering, there is no way for Qwik to know whether its data will be required by one of the children of that component (or grandchildren), so the optimizer marks a component as dynamic and all loaders data are serialized, even if the data are not required later.
Due to the
{condition.value ? <Child /> : <div/>}
condition, the component is marked as dynamic. This is because we don't know if the<Child />
component calls theuseProductDetails()
. In that case, we need the data for the<Child />
component.Goals you are trying to achieve:
Any other context or information you want to share:
Proposed Solution / Feature
What do you propose?
The loader data will never serialized from context. After SSR, the data will always be discarded if it is not "captured".
If a child component uses the route loader again, we will lazy load the data as needed.
Additionally, provide an option
persist: boolean
torouteLoader$
to serialize the state anyway if developers want it.export interface CommonLoaderActionOptions { readonly id?: string; readonly validation?: DataValidator[]; + readonly persist?: boolean; }
Code examples
In above example the
useProductDetails
data are not serialized.If the
Child
component is rendered, the data are lazy loaded through the server.In above example the
useProductDetails
data are serialized, becausepersist
option is passed.If the
Child
component is rendered, the data are reused from state.Links / References
No response
Beta Was this translation helpful? Give feedback.
All reactions