-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
kit start mounting wrong node #4685
Comments
I've opened #4698, which solves this, but at the cost of an additional element in all server-rendered HTML. While working on it, it occurred to me that you could probably achieve the same outcome using const pattern = /data-hydrate="(.+)"/;
const response = await resolve(event, {
transformPage: ({ html }) => html
.replace(/<script[^]+?<\/script>/g, (script) => {
const match = pattern.exec(script);
return match ? `<span ${match[1]}/>${script.replace(pattern, '')}` : script;
})
}); |
@Rich-Harris you're so fast! Thank you! We're already doing the string manipulation you suggest in the comment. The concern with that approach is that it's modifying an internal sveltekit implementation detail that could change without warning. If y'all are aware of this edge case and don't think anything about the current implementation will change in the future, I'm super happy keeping that string replacing as our final solution! Otherwise, #4698 looks great! |
) * add test to prevent accidental breakage of data-hydrate mechanism - closes #4685 * change data-hydrate to data-sveltekit-hydrate * changeset
Thanks, folks! |
@Rich-Harris it looks like this may have regressed. Would you recommend we manage the html script ourselves? |
Describe the bug
For a number of reasons related to platform integration, nytimes wraps sveltekit html output in a template that will occasionally hoist script tags into the
body
tag:src/hooks.js
Since kit now assumes that the mount script is always an immediate child of the root mount node, this means that kit will mount the
body
node instead of the parentNode defined in app.html template.In practice this means that if we wanted to embed a component generated by kit into the NYTs homepage (which hoists scripts), we're at risk of that component blowing out the entire DOM.
I really like the ergonomics introduced in #3674, but I wonder if instead setting
data-hydrate
on<script data-hydrate="foo" />
we set it on a tag that's not vulnerable to hoisting<div data-hydrate="foo" />
Thanks so much for all the amazing work y'all have done so far. And thanks in advance for your wisdom on this.
Reproduction
In src/hooks.js write a small script that hoists kit script tags out of their default parent node.
Logs
No response
System Info
Severity
blocking an upgrade
Additional Information
No response
The text was updated successfully, but these errors were encountered: