diff --git a/packages/svelte/src/internal/server/index.js b/packages/svelte/src/internal/server/index.js index e9b18cb87d..27aa62014c 100644 --- a/packages/svelte/src/internal/server/index.js +++ b/packages/svelte/src/internal/server/index.js @@ -18,7 +18,7 @@ import { ssr_context, pop, push, set_ssr_context } from './context.js'; import { EMPTY_COMMENT, BLOCK_CLOSE, BLOCK_OPEN, BLOCK_OPEN_ELSE } from './hydration.js'; import { validate_store } from '../shared/validate.js'; import { is_boolean_attribute, is_raw_text_element, is_void } from '../../utils.js'; -import { Payload, TreeState } from './payload.js'; +import { Payload, SSRState } from './payload.js'; import { abort } from './abort-signal.js'; import { async_mode_flag } from '../flags/index.js'; import * as e from './errors.js'; @@ -62,7 +62,7 @@ export function element(payload, tag, attributes_fn = noop, children_fn = noop) * @param {{ props?: Omit; context?: Map; idPrefix?: string }} [options] */ function open(mode, component, options = {}) { - const payload = new Payload(new TreeState(mode, options.idPrefix ? options.idPrefix + '-' : '')); + const payload = new Payload(new SSRState(mode, options.idPrefix ? options.idPrefix + '-' : '')); payload.push(BLOCK_OPEN); diff --git a/packages/svelte/src/internal/server/payload.js b/packages/svelte/src/internal/server/payload.js index f21b35c432..3f306cd589 100644 --- a/packages/svelte/src/internal/server/payload.js +++ b/packages/svelte/src/internal/server/payload.js @@ -59,7 +59,7 @@ export class Payload { /** * State which is associated with the content tree as a whole. * It will be re-exposed, uncopied, on all children. - * @type {TreeState} + * @type {SSRState} * @readonly */ global; @@ -73,7 +73,7 @@ export class Payload { local; /** - * @param {TreeState} global + * @param {SSRState} global * @param {{ select_value: string | undefined }} [local] * @param {Payload | undefined} [parent] * @param {PayloadType} [type] @@ -361,7 +361,7 @@ export class Payload { } } -export class TreeState { +export class SSRState { /** @readonly @type {'sync' | 'async'} */ mode; diff --git a/packages/svelte/src/internal/server/payload.test.ts b/packages/svelte/src/internal/server/payload.test.ts index 6908fb8c96..4463e1f7fa 100644 --- a/packages/svelte/src/internal/server/payload.test.ts +++ b/packages/svelte/src/internal/server/payload.test.ts @@ -1,8 +1,8 @@ import { assert, expect, test } from 'vitest'; -import { Payload, TreeState } from './payload.js'; +import { Payload, SSRState } from './payload.js'; test('collects synchronous body content by default', () => { - const payload = new Payload(new TreeState('sync')); + const payload = new Payload(new SSRState('sync')); payload.push('a'); payload.child(($$payload) => { $$payload.push('b'); @@ -15,7 +15,7 @@ test('collects synchronous body content by default', () => { }); test('child type switches content area (head vs body)', () => { - const payload = new Payload(new TreeState('sync')); + const payload = new Payload(new SSRState('sync')); payload.push('a'); payload.child(($$payload) => { $$payload.push('T'); @@ -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 TreeState('sync'), undefined, undefined, 'head'); + const parent = new Payload(new SSRState('sync'), undefined, undefined, 'head'); parent.push(''); parent.child(($$payload) => { $$payload.push(''); @@ -39,7 +39,7 @@ test('child inherits parent type when not specified', () => { }); test('get_path returns the path indexes to a payload', () => { - const root = new Payload(new TreeState('sync')); + const root = new Payload(new SSRState('sync')); let child_a: InstanceType | undefined; let child_b: InstanceType | undefined; let child_b_0: InstanceType | undefined; @@ -63,7 +63,7 @@ test('get_path returns the path indexes to a payload', () => { }); test('creating an async child in a sync context throws', () => { - const payload = new Payload(new TreeState('sync')); + const payload = new Payload(new SSRState('sync')); payload.push('a'); expect(() => payload.child(async ($$payload) => { @@ -74,7 +74,7 @@ test('creating an async child in a sync context throws', () => { }); test('collect_async allows awaiting payload to get aggregated content', async () => { - const payload = new Payload(new TreeState('async')); + const payload = new Payload(new SSRState('async')); payload.push('1'); payload.child(async ($$payload) => { await Promise.resolve(); @@ -87,7 +87,7 @@ test('collect_async allows awaiting payload to get aggregated content', async () }); test('compact synchronously aggregates a range and can transform into head/body', () => { - const payload = new Payload(new TreeState('sync')); + const payload = new Payload(new SSRState('sync')); payload.push('a'); payload.push('b'); payload.push('c'); @@ -105,7 +105,7 @@ test('compact synchronously aggregates a range and can transform into head/body' }); test('compact schedules followup when compaction input is async', async () => { - const payload = new Payload(new TreeState('async')); + const payload = new Payload(new SSRState('async')); payload.push('a'); payload.child(async ($$payload) => { await Promise.resolve(); @@ -124,7 +124,7 @@ test('compact schedules followup when compaction input is async', async () => { }); test('copy creates a deep copy of the tree and shares promises reference', () => { - const payload = new Payload(new TreeState('sync')); + const payload = new Payload(new SSRState('sync')); let child_ref: InstanceType | undefined; payload.child(($$payload) => { child_ref = $$payload; @@ -147,7 +147,7 @@ test('copy creates a deep copy of the tree and shares promises reference', () => }); test('local state is shallow-copied to children', () => { - const root = new Payload(new TreeState('sync')); + const root = new Payload(new SSRState('sync')); root.local.select_value = 'A'; let child: InstanceType | undefined; root.child(($$payload) => { @@ -160,11 +160,11 @@ test('local state is shallow-copied to children', () => { }); test('subsume replaces tree content and state from other', () => { - const a = new Payload(new TreeState('async'), undefined, undefined, 'head'); + const a = new Payload(new SSRState('async'), undefined, undefined, 'head'); a.push(''); a.local.select_value = 'A'; - const b = new Payload(new TreeState('async')); + const b = new Payload(new SSRState('async')); b.child(async ($$payload) => { await Promise.resolve(); $$payload.push('body'); @@ -182,11 +182,11 @@ test('subsume replaces tree content and state from other', () => { }); test('subsume refuses to switch modes', () => { - const a = new Payload(new TreeState('sync'), undefined, undefined, 'head'); + const a = new Payload(new SSRState('sync'), undefined, undefined, 'head'); a.push(''); a.local.select_value = 'A'; - const b = new Payload(new TreeState('async')); + const b = new Payload(new SSRState('async')); b.child(async ($$payload) => { await Promise.resolve(); $$payload.push('body'); @@ -202,12 +202,12 @@ test('subsume refuses to switch modes', () => { }); test('TreeState uid generator uses prefix', () => { - const state = new TreeState('sync', 'id-'); + const state = new SSRState('sync', 'id-'); assert.equal(state.uid(), 'id-s1'); }); test('TreeState title ordering favors later lexicographic paths', () => { - const state = new TreeState('sync'); + const state = new SSRState('sync'); state.set_title('A', [1]); assert.equal(state.get_title(), 'A'); @@ -234,7 +234,7 @@ test('TreeState title ordering favors later lexicographic paths', () => { }); test('push accepts async functions in async context', async () => { - const payload = new Payload(new TreeState('async')); + const payload = new Payload(new SSRState('async')); payload.push('a'); payload.push(async () => { await Promise.resolve(); @@ -248,7 +248,7 @@ test('push accepts async functions in async context', async () => { }); test('push handles async functions with different timing', async () => { - const payload = new Payload(new TreeState('async')); + const payload = new Payload(new SSRState('async')); // Fast async function payload.push(async () => { @@ -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 TreeState('async'), undefined, undefined, 'head'); + const payload = new Payload(new SSRState('async'), undefined, undefined, 'head'); payload.push(async () => { await Promise.resolve(); return 'Async Title'; @@ -283,7 +283,7 @@ test('push async functions work with head content type', async () => { }); test('push async functions can be mixed with child payloads', async () => { - const payload = new Payload(new TreeState('async')); + const payload = new Payload(new SSRState('async')); payload.push('start-'); payload.push(async () => { @@ -303,7 +303,7 @@ test('push async functions can be mixed with child payloads', async () => { }); test('push async functions work with compact operations', async () => { - const payload = new Payload(new TreeState('async')); + const payload = new Payload(new SSRState('async')); payload.push('a'); payload.push(async () => { await Promise.resolve(); @@ -322,7 +322,7 @@ test('push async functions work with compact operations', async () => { }); test('push async functions are not supported in sync context', () => { - const payload = new Payload(new TreeState('sync')); + const payload = new Payload(new SSRState('sync')); payload.push('a'); expect(() => { @@ -332,7 +332,7 @@ test('push async functions are not supported in sync context', () => { }); test('collect_on_destroy yields callbacks in the correct order', async () => { - const payload = new Payload(new TreeState('async')); + const payload = new Payload(new SSRState('async')); const destroyed: string[] = []; payload.component((payload) => { payload.on_destroy(() => destroyed.push('a'));