Skip to content

Commit 4826e2f

Browse files
committed
[fix] avoid unnecessary $page store updates
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 57e8d1a commit 4826e2f

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

.changeset/wise-otters-swim.md

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

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

160-
const serialized = { data: '', form: 'null' };
160+
const serialized = { data: '', form: 'null', error: 'null' };
161161

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

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

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

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

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

0 commit comments

Comments
 (0)