-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle hydration inside hydration (resolve nested hydration) #244
Comments
Looks like something I was trying to solve in 23ddb74#diff-8dbdaa04b760b0b6f61e99750b86f672deb58b0f165df0dac1416e941e89832fR24 - let svelte compiler handle the template for loading another (hydrated) component using In that commit, you can use the <ComponentPage hydrate-client={{ prop: null }} hydrate-options={{loading: process.env.LIVE_UPDATE ? 'lazy' : 'none'}} /> <NestedComponent hydrate-client={{ prop2: null }} hydrate-options={{loading: process.env.componentType === "server" ? "lazy" : "none"}} /> But then it was reverted. In the future Elderjs will be able to load hydrated components from multiple frameworks, so writing something like Or we have to improve the template to something like: {#if hydrateOptions.loading === 'none' && componentType === 'svelte'}
... insert component literally ...
{#else}
... insert partial hydration placeholder ...
{/if} Just have to scan the file tree to determine component type from its name. |
As a quick fix, maybe we can change that error into a warning so it won't interrupt the build. |
Maybe this should be handled at compile time? When compiling client components, we can replace <Component hydrate-client={props} /> with <Component {...props} /> instead of <ejswrapper data-ejs-component="Component" data-ejs-props={JSON.stringify(props)} data-... |
Please try #258. You can install that branch by running:
|
I have a following scenario:
There are some pages with several hydrated components.
However, I need two variants of site build: 'live-update' and 'static'.
Live-update will monitor some data from CMS system and re-render the page if the data there changes without the need to rebuild the whole site. For this purpose I need the whole page to be a hydrated component, and that's where the problem of nested hydration comes.
The scheme to handle this is the following. There's a wrapper in route template:
And now to resolve nested components inside ComponentPage another wrapper is needed:
However, this brings error in @elderjs/elderjs/build/partialHydration/mountComponentsInHtml.js with this piece of code:
What's curious, this code could be commented out and everything will work as expected, because, in fact, nested hydration never actually happens (process.env.componentType resolves this).
Keeping all that above in mind, I'd like to ask if it's possible to make this behavior default or automatic without a wrapper.
So, hydrate-client={{prop: null}} will automatically be changed into prop={null} for all nested hydrated components, or, at least gave only a warning.
The text was updated successfully, but these errors were encountered: