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 all 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
14 changes: 13 additions & 1 deletion 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,16 @@
}
};
}

if (browser) {
const h3 = document.createElement('h3');
const text = document.createTextNode('I should not be rendered');
h3.appendChild(text);
const parentDiv = document.getElementById('nested-layout-reset-test');
if (parentDiv) {
parentDiv.appendChild(h3);
}
}
</script>

<script>
Expand All @@ -22,7 +34,7 @@
export let foo;
</script>

<slot></slot>
<slot />

<footer>{foo.bar}</footer>

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" />