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] Import fallback components when they are actually required #2160

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kit/src/core/create_app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function generate_client_manifest(manifest_data, base) {

export const routes = ${routes};

export const fallback = [c[0](), c[1]()];
export const fallback = [c[0], c[1]];
`);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function initial_fetch(resource, opts) {
export class Renderer {
/** @param {{
* Root: CSRComponent;
* fallback: [CSRComponent, CSRComponent];
* fallback: [() => CSRComponent, () => CSRComponent];
* target: Node;
* session: any;
* host: string;
Expand Down Expand Up @@ -708,7 +708,7 @@ export class Renderer {
};

const node = await this._load_node({
module: await this.fallback[0],
module: await this.fallback[0](),
page,
context: {}
});
Expand All @@ -718,7 +718,7 @@ export class Renderer {
await this._load_node({
status,
error,
module: await this.fallback[1],
module: await this.fallback[1](),
page,
context: (node && node.loaded && node.loaded.context) || {}
})
Expand Down
9 changes: 9 additions & 0 deletions packages/kit/test/apps/basics/src/routes/__layout.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script context="module">
import { browser } from '$app/env';

/** @type {import('@sveltejs/kit').Load} */
export async function load() {
return {
Expand All @@ -9,6 +11,13 @@
}
};
}

if (browser) {
let h3 = document.createElement('h3');
benmccann marked this conversation as resolved.
Show resolved Hide resolved
let text = document.createTextNode('You cannot reset me');
benmccann marked this conversation as resolved.
Show resolved Hide resolved
h3.appendChild(text);
document.getElementById('nested-layout-reset-test')?.appendChild(h3);
benmccann marked this conversation as resolved.
Show resolved Hide resolved
}
</script>

<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ export default function (test) {
assert.equal(await page.textContent('h1'), 'Layout reset');
assert.equal(await page.textContent('h2'), 'Hello');
});

test('context script reset', '/nested-layout/reset', async ({ page }) => {
assert.ok(await page.evaluate(() => !document.querySelector('h3')));
});
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<h2>Hello</h2>
<h2>Hello</h2>
<div id="nested-layout-reset-test" />