Skip to content

Commit

Permalink
fix: properly purge server load cache (#8893)
Browse files Browse the repository at this point in the history
fixes #8272

When going from a page with server load to a page without server load, the cache wasn't purged properly

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
  • Loading branch information
coyotte508 and dummdidumm authored Feb 7, 2023
1 parent c9e491a commit 1beb19c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fast-rules-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: don't reuse previous server load cache when there's no server load function
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ export function create_client({ target }) {
// server_data_node is undefined if it wasn't reloaded from the server;
// and if current loader uses server data, we want to reuse previous data.
server_data_node === undefined && loader[0] ? { type: 'skip' } : server_data_node ?? null,
previous?.server
loader[0] ? previous?.server : undefined
)
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('./$types').LayoutServerLoad} */
export function load(input) {
return {
title: input.url.pathname
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot />
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export let data;
</script>

<p>Page without load</p>

<pre>{JSON.stringify(data)}</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('./$types').PageServerLoad} */
export function load() {
return { server: true };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
/** @type {import('./$types').PageData} */
export let data;
</script>

<p>Page with server load</p>

<pre>{JSON.stringify(data)}</pre>
16 changes: 16 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ test.describe('Load', () => {
);
await app.goto('/load/server-data-reuse/no-load');
expect(await page.textContent('pre')).toBe(JSON.stringify({ foo: { bar: 'Custom layout' } }));

await page.goto('/load/server-data-reuse/with-changing-parent/with-server-load');
expect(await page.textContent('pre')).toBe(
JSON.stringify({
foo: { bar: 'Custom layout' },
title: '/load/server-data-reuse/with-changing-parent/with-server-load',
server: true
})
);
await app.goto('/load/server-data-reuse/with-changing-parent/no-load');
expect(await page.textContent('pre')).toBe(
JSON.stringify({
foo: { bar: 'Custom layout' },
title: '/load/server-data-reuse/with-changing-parent/no-load'
})
);
});

test('keeps server data when valid while not reusing client load data', async ({
Expand Down

0 comments on commit 1beb19c

Please sign in to comment.