Home / Class/ SSRState Class — svelte Architecture

SSRState Class — svelte Architecture

Architecture documentation for the SSRState class in renderer.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  27e4b187_7d63_5de0_1c16_1569e67253dd["SSRState"]
  25166256_49ce_81f2_0877_fdbc689bed91["renderer.js"]
  27e4b187_7d63_5de0_1c16_1569e67253dd -->|defined in| 25166256_49ce_81f2_0877_fdbc689bed91
  1d598ca7_4e67_ce15_0c12_da72efbc960c["constructor()"]
  27e4b187_7d63_5de0_1c16_1569e67253dd -->|method| 1d598ca7_4e67_ce15_0c12_da72efbc960c
  a6cc05f4_ce0b_dde9_2c41_cf973a86aeb9["get_title()"]
  27e4b187_7d63_5de0_1c16_1569e67253dd -->|method| a6cc05f4_ce0b_dde9_2c41_cf973a86aeb9
  658aea3c_3677_5e23_97a5_866bbdc9fd99["set_title()"]
  27e4b187_7d63_5de0_1c16_1569e67253dd -->|method| 658aea3c_3677_5e23_97a5_866bbdc9fd99

Relationship Graph

Source Code

packages/svelte/src/internal/server/renderer.js lines 723–781

export class SSRState {
	/** @readonly @type {Csp & { script_hashes: Sha256Source[] }} */
	csp;

	/** @readonly @type {'sync' | 'async'} */
	mode;

	/** @readonly @type {() => string} */
	uid;

	/** @readonly @type {Set<{ hash: string; code: string }>} */
	css = new Set();

	/** @type {{ path: number[], value: string }} */
	#title = { path: [], value: '' };

	/**
	 * @param {'sync' | 'async'} mode
	 * @param {string} id_prefix
	 * @param {Csp} csp
	 */
	constructor(mode, id_prefix = '', csp = { hash: false }) {
		this.mode = mode;
		this.csp = { ...csp, script_hashes: [] };

		let uid = 1;
		this.uid = () => `${id_prefix}s${uid++}`;
	}

	get_title() {
		return this.#title.value;
	}

	/**
	 * Performs a depth-first (lexicographic) comparison using the path. Rejects sets
	 * from earlier than or equal to the current value.
	 * @param {string} value
	 * @param {number[]} path
	 */
	set_title(value, path) {
		const current = this.#title.path;

		let i = 0;
		let l = Math.min(path.length, current.length);

		// skip identical prefixes - [1, 2, 3, ...] === [1, 2, 3, ...]
		while (i < l && path[i] === current[i]) i += 1;

		if (path[i] === undefined) return;

		// replace title if
		// - incoming path is longer - [7, 8, 9] > [7, 8]
		// - incoming path is later  - [7, 8, 9] > [7, 8, 8]
		if (current[i] === undefined || path[i] > current[i]) {
			this.#title.path = path;
			this.#title.value = value;
		}
	}
}

Domain

Frequently Asked Questions

What is the SSRState class?
SSRState is a class in the svelte codebase, defined in packages/svelte/src/internal/server/renderer.js.
Where is SSRState defined?
SSRState is defined in packages/svelte/src/internal/server/renderer.js at line 723.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free