-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Full Page Rendering #577
Comments
Finally starting to dig into this. I actually thought that full-page rendering in the sense of SSR'ing a document (as opposed to a fragment) wasn't possible — that maybe it would choke on The more I think about this, the less sure I am about full-page rendering in the client. A lot of what goes inside a So while Svelte could in theory pull out the 'mutable' bits of Would be great to get hydration with or without this. Having thought about it for a bit I reckon it'd be good to avoid checksums — it makes it hard to do things like this, where {{#if loading}}
<p>loading, please wait</p>
{{else}}
<div>
we are interactive
</div>
{{/if}} I wonder if we could do something like this: // without hydration
function create_main_fragment(state, component) {
var text_value, nodes;
return {
mount (target, anchor) {
nodes = [
createElement('h1'),
createText('hello '),
createText(text_value = state.name),
createText('!')
];
appendNode(nodes[0], nodes[1]);
appendNode(nodes[0], nodes[2]);
appendNode(nodes[0], nodes[3];
appendNode(target, nodes[0]);
},
// ...
};
}
// with hydration
function create_main_fragment(state, component) {
var text_value, nodes;
return {
mount (target, anchor) {
nodes = hydrate(target, [
{
name: 'h1',
children: [
'hello ',
text_value = state.name,
'!'
]
}
]);
},
// ...
};
} ...where |
@Rich-Harris I can understand your hesitation re full page rendering and your concerns are valid. In practise I have had no issues doing this with react. Another thing that's nice about reacts implementation is that it can tell the difference between server rendered nodes and client inserted ones. This way you can have the best of both worlds if you need to handle load events and such as you mentioned. Having said that another way to achieve the same effect is using something like react-helmet or hairdresser so it's not a deal breaker for me if that doesn't make it in although it would be nice to have an an endorsed way to do this with svelte. Hydration is much more important however. Your idea of a 'hydrate' function makes a lot of sense. My ramblings from before was merely an idea to avoid having another function inserted to keep with the 'no framework' theme. In this case it may very well make more sense to add another function though. |
I'm very interested in having hydration, I'm currently maintaining a website that renders most of the webpage through svelte serverside but currently has to just delete all the nodes the server sent since there's no hydration. |
Is this an active issue? Seems the problem was already fixed. |
Was resolved. |
Currently it is not possible to use Svelte to render/update the entire document. This feature would be useful for isomorphic apps and allows Svelte to easily update things like meta and title tags.
As discussed on gitter this would make it possible to express your entire template with Svelte and not just components inside the body tag.
Usage would look something like the following:
components/page.js
routes/home.js
Rendering
I think something that should come first is the ability to bootstrap server rendered DOM. Currently svelte always inserts or replaces an existing DOM node but this cannot work for the full document for obvious reasons.
I imagine this could be achieved by changing the 'mount' api to something like this:
(Note this is based on the HelloWorld example).
This could then be used like:
I could be way off though.
The text was updated successfully, but these errors were encountered: