Skip to content

Commit ce02847

Browse files
authored
[fix] avoid unnecessary $page store updates (#8457)
Clicking a page link and staying on the same page with nothing changing still changed the $page.store, because - form was always !== undefined (it's null) - $page.error was set to undefined after hydration, but it should be null
1 parent c413753 commit ce02847

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

.changeset/wise-otters-swim.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] avoid unnecessary $page store updates

packages/kit/src/runtime/client/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ export function create_client({ target, base }) {
467467
!current.url ||
468468
url.href !== current.url.href ||
469469
current.error !== error ||
470-
form !== undefined ||
470+
(form !== undefined && form !== page.form) ||
471471
data_changed;
472472

473473
if (page_changed) {

packages/kit/src/runtime/client/types.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface Client {
2626
// private API
2727
_hydrate(opts: {
2828
status: number;
29-
error: App.Error;
29+
error: App.Error | null;
3030
node_ids: number[];
3131
params: Record<string, string>;
3232
route: { id: string | null };

packages/kit/src/runtime/server/page/render.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export async function render_response({
158158
/** @param {string} path */
159159
const prefixed = (path) => (path.startsWith('/') ? path : `${assets}/${path}`);
160160

161-
const serialized = { data: '', form: 'null' };
161+
const serialized = { data: '', form: 'null', error: 'null' };
162162

163163
try {
164164
serialized.data = `[${branch
@@ -196,6 +196,10 @@ export async function render_response({
196196
serialized.form = uneval_action_response(form_value, /** @type {string} */ (event.route.id));
197197
}
198198

199+
if (error) {
200+
serialized.error = devalue.uneval(error);
201+
}
202+
199203
if (inline_styles.size > 0) {
200204
const content = Array.from(inline_styles.values()).join('\n');
201205

@@ -256,17 +260,14 @@ export async function render_response({
256260
const hydrate = [
257261
`node_ids: [${branch.map(({ node }) => node.index).join(', ')}]`,
258262
`data: ${serialized.data}`,
259-
`form: ${serialized.form}`
263+
`form: ${serialized.form}`,
264+
`error: ${serialized.error}`
260265
];
261266

262267
if (status !== 200) {
263268
hydrate.push(`status: ${status}`);
264269
}
265270

266-
if (error) {
267-
hydrate.push(`error: ${devalue.uneval(error)}`);
268-
}
269-
270271
if (options.embedded) {
271272
hydrate.push(`params: ${devalue.uneval(event.params)}`, `route: ${s(event.route)}`);
272273
}

0 commit comments

Comments
 (0)