-
-
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
Can't replace top-level HTML element when hydrating #5547
Comments
Here's a quick repo that demonstrates the issue: https://github.com/jimafisk/svelte-document-replace |
I'm not sure what you'd need to mount an app at |
One of our primary goals for the project is to simplify the dev experience for new folks as much as possible, so ideally the users won't even have to think about how it's getting mounted at all. Using Also when mounting We're hoping to make it so the Svelte templates tell a complete story of the dom, while limiting the number of concepts required to get started. Are there challenges to implementing something like this that I might not thinking of? Thanks for taking a look @Conduitry! |
This comment has been minimized.
This comment has been minimized.
Hi @Conduitry, would checking if the It would help our project out greatly to be able to hydrate the full dom. If this has consequences that I'm not considering, or if you think a different approach would be better please let me know! Thank you! |
I think that being able to use |
You're right, those essentially do accomplish the same thing. We're generally trying to take a content driven approach in our project wherever possible. That way a developer can set up a general template structure and from there everything is fed from the JSON source managed by a content editor. You'd still be able to set things like titles from the content source using Is there a similar mechanism for reactive attributes on the <script>
import Head from './head.svelte';
import Nav from './nav.svelte';
export let content;
let lang = "en"
const setFrench = () => {
lang = "fr";
}
</script>
<html lang="{lang}">
<Head title={content.title} />
<body>
<Nav />
<button on:click={setFrench}>Fr</button>
</body>
</html> I understand that you can't cater the project to everyone's individual preferences, so if this is a change can't pulled in it's ok to close out this issue. I appreciate you both taking the time to discuss options with me. For posterity my main concerns for our particular project are:
Thanks! |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
It looks like this might have been fixed by @hbirler on 6/22/2021: function insert(target, node, anchor) {
if (is_hydrating && !anchor) {
append(target, node);
}
else if (node.parentNode !== target || (anchor && node.nextSibling !== anchor)) {
target.insertBefore(node, anchor || null);
}
} This is amazing, thank you so much! 👏 👏 👏 |
Oh wow. I did not even know that this issue existed, so I cannot guarantee that there is no corner case where such a use-case fails. But I guess simply avoiding re-orderings when not necessary results in no exceptions being thrown in your example. |
Describe the bug
If you try to replace the
<html>
wrapper during hydration, it throws errors on line 179 ofsvelte/internal/index.mjs
because it can't insertBefore the top-level document. I'm trying to use an entrypoint in this format:Logs
DOMException: Failed to execute 'insertBefore' on 'Node': Only one element on document allowed.
DOMException: Node.insertBefore: Cannot have more than one Element child of a Document
To Reproduce
Unfortunately I don't think I can use the repl to demonstrate hydration issues. This can be seen in the default starter of https://github.com/plentico/plenti. EDIT: Added a demo that doesn't require plenti: https://github.com/jimafisk/svelte-document-replace
Expected behavior
I'd like to be able to use the top-level
document
as a target without hitting errors. I'm not sure the exact fix to minimize negative impact on other aspects of svelte would be, but a temp fix on line 178 ofnode_modules/svelte/internal/index.mjs
works for me:Stacktraces
N/A
Information about your Svelte project:
Severity
I currently have to tweak the Svelte lib to make it work with my project, but I recognize that we have a small userbase and there are higher priority items.
Additional context
The error message is the same as shown here, although that seems to be related to a slightly different issue.
Here's another conversation about replacing top-level elements during hydration: https://stackoverflow.com/questions/61640429/how-to-replace-the-contents-of-a-target-in-svelte-instead-of-appending-to-childr
Thank you!
The text was updated successfully, but these errors were encountered: