-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sveltekit nodes are clobbering each other in "embedded" mode #9576
Comments
Adding a note to myself to help understand the issue: |
Sorry for the slow reply @john-michael-murphy! The hash in the global variable is derived from Ideally the hash would be based on the version and the URL that's being rendered. @ejmurra's PR (hi Eli! I don't think we've met, but any NYTG member is a friend of mine) is close to this, but uses the route instead of the URL which probably isn't enough (you could have two embeds from the same route, if it used dynamic parameters). The wrinkle is that I think that approach would break the kit/packages/kit/src/exports/vite/index.js Lines 339 to 341 in 04837c0
But! I don't think it's a problem that I think this would work (in other words, putting everything inside the outer curlies so that we can create a local <script>
{
__sveltekit_17vqb19 = {
env: {},
base: new URL(".", location).pathname.slice(0, -1)
};
+ const element = document.currentScript.parentElement;
const data = [{...}] // page specific props;
Promise.all([
import("./_app/immutable/entry/start.d2ffe299.js"),
import("./_app/immutable/entry/app.ef056721.js")
]).then(([kit, app]) => {
+ kit.start(app, element, {
node_ids: [0, 2],
data,
form: null,
error: null,
params: {},
route: {...}
});
});
}
</script> If that seems like a good solution then that's an easy fix we can make. |
Hi @Rich-Harris! I've been a svelte user for a while now (we used Sapper to build our covid pages when I was at the Tampa Bay Times) so I'm really excited to get a chance to make a lil contribution here. Everything you've said makes sense to me - I didn't consider dynamic parameter routes and the need for it to be known at build. I can take a stab implementing this this weekend. I've also been familiarizing myself with the test suite so I think I can write an integration test for this as part of the |
@Rich-Harris, now it's my turn to apologize for a slow reply! This solution seems fine to me as long as we don't need that element defined globally! |
While we're looking at |
Describe the bug
Consider the scenario where Sveltekit is building pages in embedded mode.
In this scenario, Sveltekit generates two pages:
a.html
andb.html
.Both
a
andb
are then embedded into a single page:When Sveltekit builds these pages, it inlines the following hydration script (or something similar) into both pages:
Both pages define the same global variable (in this example,
__sveltekit_17vqb19
). This putsa.html
andb.html
in a race condition to define and mount that variable.This race condition leads
a.html
andb.html
mounting and blowing each other out of the water.Reproduction
a
andb
.a.html
andb.html
into a third pagec.html
.Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
The NYTs has been so happy with Sveltekit and can't thank you enough for all the great work y'all have done.
The text was updated successfully, but these errors were encountered: