Skip to content
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

Fix inconsistent rendering of shadow routes on client/server-side #3780

Merged
5 changes: 5 additions & 0 deletions .changeset/curvy-experts-try.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fixes a bug with same module client-side navigation for shadow routes
6 changes: 5 additions & 1 deletion packages/kit/src/runtime/client/renderer.js
Expand Up @@ -615,6 +615,9 @@ export class Renderer {
if (props) {
// shadow endpoint props means we need to mark this URL as a dependency of itself
node.uses.dependencies.add(url.href);
for (const key in params) {
PH4NTOMiki marked this conversation as resolved.
Show resolved Hide resolved
node.uses.params.add(key);
}
}

/** @type {Record<string, string>} */
Expand Down Expand Up @@ -743,6 +746,7 @@ export class Renderer {
!previous ||
module !== previous.module ||
(changed.url && previous.uses.url) ||
(has_shadow && i === a.length - 1) ||
changed.params.some((param) => previous.uses.params.has(param)) ||
(changed.session && previous.uses.session) ||
Array.from(previous.uses.dependencies).some((dep) => this.invalid.has(dep)) ||
Expand All @@ -754,7 +758,7 @@ export class Renderer {

if (has_shadow && i === a.length - 1) {
const res = await fetch(
`${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}__data.json`,
`${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}__data.json${url.search}`,
{
headers: {
'x-sveltekit-noredirect': 'true'
Expand Down
5 changes: 5 additions & 0 deletions packages/kit/src/runtime/server/index.js
Expand Up @@ -141,6 +141,11 @@ export async function respond(request, options, state = {}) {
if (!match) continue;

event.params = route.params ? decode_params(route.params(match)) : {};
if (event.url.pathname.endsWith(DATA_SUFFIX)) {
event.url = new URL(
event.url.origin + event.url.pathname.slice(0, -DATA_SUFFIX.length) + event.url.search
);
}

/** @type {Response | undefined} */
let response;
Expand Down