From 1f5f385fe56afa249aa06dc07e3ae27948c3252c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 17 Sep 2025 09:49:38 -0400 Subject: [PATCH] grab this.local from parent directly --- packages/svelte/src/internal/server/payload.js | 15 +++++++-------- .../svelte/src/internal/server/payload.test.ts | 8 ++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/svelte/src/internal/server/payload.js b/packages/svelte/src/internal/server/payload.js index f0acf07a3a..4f0df227cf 100644 --- a/packages/svelte/src/internal/server/payload.js +++ b/packages/svelte/src/internal/server/payload.js @@ -74,13 +74,12 @@ export class Payload { /** * @param {SSRState} global - * @param {{ select_value: string | undefined }} [local] * @param {Payload | undefined} [parent] * @param {PayloadType} [type] */ - constructor(global, local = { select_value: undefined }, parent, type) { + constructor(global, parent, type) { this.global = global; - this.local = { ...local }; + this.local = parent ? { ...parent.local } : { select_value: undefined }; this.#parent = parent; this.type = type ?? parent?.type ?? 'body'; } @@ -93,7 +92,7 @@ export class Payload { * @returns {void} */ child(render, type) { - const child = new Payload(this.global, this.local, this, type); + const child = new Payload(this.global, this, type); this.#run_child(child, render); } @@ -106,7 +105,7 @@ export class Payload { */ component(render, fn) { push(fn); - const child = new Payload(this.global, this.local, this); + const child = new Payload(this.global, this); child.#is_component_body = true; this.#run_child(child, render); pop(); @@ -129,7 +128,7 @@ export class Payload { * @param {{ start: number, end?: number, fn: (content: AccumulatedContent) => AccumulatedContent | Promise }} args */ compact({ start, end = this.#out.length, fn }) { - const child = new Payload(this.global, this.local, this); + const child = new Payload(this.global, this); const to_compact = this.#out.splice(start, end - start, child); if (this.global.mode === 'sync') { @@ -188,7 +187,7 @@ export class Payload { * @deprecated this is needed for legacy component bindings */ copy() { - const copy = new Payload(this.global, this.local, this.#parent, this.type); + const copy = new Payload(this.global, this.#parent, this.type); copy.#out = this.#out.map((item) => (item instanceof Payload ? item.copy() : item)); copy.promises = this.promises; return copy; @@ -358,7 +357,7 @@ export class Payload { static #push_accumulated_content(tree, accumulated_content) { for (const [type, content] of Object.entries(accumulated_content)) { if (!content) continue; - const child = new Payload(tree.global, tree.local, tree, /** @type {PayloadType} */ (type)); + const child = new Payload(tree.global, tree, /** @type {PayloadType} */ (type)); child.push(content); tree.#out.push(child); } diff --git a/packages/svelte/src/internal/server/payload.test.ts b/packages/svelte/src/internal/server/payload.test.ts index 4463e1f7fa..a36404405b 100644 --- a/packages/svelte/src/internal/server/payload.test.ts +++ b/packages/svelte/src/internal/server/payload.test.ts @@ -28,7 +28,7 @@ test('child type switches content area (head vs body)', () => { }); test('child inherits parent type when not specified', () => { - const parent = new Payload(new SSRState('sync'), undefined, undefined, 'head'); + const parent = new Payload(new SSRState('sync'), undefined, 'head'); parent.push(''); parent.child(($$payload) => { $$payload.push(''); @@ -160,7 +160,7 @@ test('local state is shallow-copied to children', () => { }); test('subsume replaces tree content and state from other', () => { - const a = new Payload(new SSRState('async'), undefined, undefined, 'head'); + const a = new Payload(new SSRState('async'), undefined, 'head'); a.push(''); a.local.select_value = 'A'; @@ -182,7 +182,7 @@ test('subsume replaces tree content and state from other', () => { }); test('subsume refuses to switch modes', () => { - const a = new Payload(new SSRState('sync'), undefined, undefined, 'head'); + const a = new Payload(new SSRState('sync'), undefined, 'head'); a.push(''); a.local.select_value = 'A'; @@ -271,7 +271,7 @@ test('push handles async functions with different timing', async () => { }); test('push async functions work with head content type', async () => { - const payload = new Payload(new SSRState('async'), undefined, undefined, 'head'); + const payload = new Payload(new SSRState('async'), undefined, 'head'); payload.push(async () => { await Promise.resolve(); return 'Async Title';