Skip to content

[fix] load function should not leak props #2356

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

Merged
merged 2 commits into from
Sep 3, 2021
Merged
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
5 changes: 5 additions & 0 deletions .changeset/polite-elephants-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] load function should not leak props to other components
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export class Renderer {

for (let i = 0; i < filtered.length; i += 1) {
const loaded = filtered[i].loaded;
if (loaded) result.props[`props_${i}`] = await loaded.props;
result.props[`props_${i}`] = loaded ? await loaded.props : null;
}

if (
Expand Down
8 changes: 8 additions & 0 deletions packages/kit/test/apps/basics/src/routes/load/_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,12 @@ export default function (test, is_dev) {
assert.equal(await page.innerHTML('.parsed'), '{"oddly":{"formatted":"json"}}');
assert.equal(await page.innerHTML('.raw'), '{ "oddly" : { "formatted" : "json" } }');
});

test('does not leak props to other pages', '/load/props/about', async ({ page, clicknav }) => {
assert.equal(await page.textContent('p'), 'Data: undefined');
await clicknav('[href="/load/props/"]');
assert.equal(await page.textContent('p'), 'Data: Hello from Index!');
await clicknav('[href="/load/props/about"]');
assert.equal(await page.textContent('p'), 'Data: undefined');
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<header>
<nav>
<a href="/load/props/">Index</a>
<a href="/load/props/about">About</a>
</nav>
</header>

<main>
<slot />
</main>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export let data = 'undefined';
</script>

<h3>About</h3>

<p>Data: {data}</p>
14 changes: 14 additions & 0 deletions packages/kit/test/apps/basics/src/routes/load/props/index.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script context="module">
export async function load() {
const data = 'Hello from Index!';
return { props: { data } };
}
</script>

<script>
export let data = 'undefined';
</script>

<h3>Index</h3>

<p>Data: {data}</p>