Home / File/ await.js — svelte Source File

await.js — svelte Source File

Architecture documentation for await.js, a javascript file in the svelte codebase. 26 imports, 0 dependents.

File javascript ClientRuntime Hydration 26 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f["await.js"]
  cb946435_ce66_d1e8_6bee_287bdb07e7c5["utils.js"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> cb946435_ce66_d1e8_6bee_287bdb07e7c5
  b898b311_bec4_34ca_1aa6_2a0ff69b0212["is_promise"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> b898b311_bec4_34ca_1aa6_2a0ff69b0212
  1ae6fa4e_16ee_acdf_5e28_17eb0819fddb["effects.js"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> 1ae6fa4e_16ee_acdf_5e28_17eb0819fddb
  1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b["block"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> 1bd7dd6f_4c22_6f44_9747_fc5ea0deaa7b
  e5c35d51_28d8_9054_923d_b7f82a3c8dc2["sources.js"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> e5c35d51_28d8_9054_923d_b7f82a3c8dc2
  fc566ca0_2101_ea1a_cf42_44d2442cc526["internal_set"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> fc566ca0_2101_ea1a_cf42_44d2442cc526
  03788141_01d2_5299_6e22_4211e661afe4["mutable_source"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> 03788141_01d2_5299_6e22_4211e661afe4
  1e2f7428_6050_5cb7_69db_bf5db719f6d1["source"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> 1e2f7428_6050_5cb7_69db_bf5db719f6d1
  f3948b0d_b92a_0767_ba6c_832767f4e2bb["hydration.js"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> f3948b0d_b92a_0767_ba6c_832767f4e2bb
  b31601aa_35ce_7827_5394_99fb97fa27d2["hydrate_next"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> b31601aa_35ce_7827_5394_99fb97fa27d2
  8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e["skip_nodes"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> 8bcc1a1c_73ab_4fe7_59be_b28bbe88fd3e
  40f27ad3_30bb_8f2a_3fb3_757088cf7428["set_hydrate_node"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> 40f27ad3_30bb_8f2a_3fb3_757088cf7428
  f5b61c69_d41c_bdb7_b931_5b8b3374332c["set_hydrating"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> f5b61c69_d41c_bdb7_b931_5b8b3374332c
  8e9a8b22_9754_09a3_8bf1_af0aeb68deca["task.js"]
  277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f --> 8e9a8b22_9754_09a3_8bf1_af0aeb68deca
  style 277e61a1_318f_c1a6_cf40_f6e1a0f3aa2f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { Source, TemplateNode } from '#client' */
import { is_promise } from '../../../shared/utils.js';
import { block } from '../../reactivity/effects.js';
import { internal_set, mutable_source, source } from '../../reactivity/sources.js';
import {
	hydrate_next,
	hydrating,
	skip_nodes,
	set_hydrate_node,
	set_hydrating
} from '../hydration.js';
import { queue_micro_task } from '../task.js';
import { HYDRATION_START_ELSE, UNINITIALIZED } from '../../../../constants.js';
import { is_runes } from '../../context.js';
import { Batch, flushSync, is_flushing_sync } from '../../reactivity/batch.js';
import { BranchManager } from './branches.js';
import { capture, unset_context } from '../../reactivity/async.js';

const PENDING = 0;
const THEN = 1;
const CATCH = 2;

/** @typedef {typeof PENDING | typeof THEN | typeof CATCH} AwaitState */

/**
 * @template V
 * @param {TemplateNode} node
 * @param {(() => any)} get_input
 * @param {null | ((anchor: Node) => void)} pending_fn
 * @param {null | ((anchor: Node, value: Source<V>) => void)} then_fn
 * @param {null | ((anchor: Node, error: unknown) => void)} catch_fn
 * @returns {void}
 */
export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
	if (hydrating) {
		hydrate_next();
	}

	var runes = is_runes();

	var v = /** @type {V} */ (UNINITIALIZED);
	var value = runes ? source(v) : mutable_source(v, false, false);
	var error = runes ? source(v) : mutable_source(v, false, false);

	var branches = new BranchManager(node);

	block(() => {
		var input = get_input();
		var destroyed = false;

		/** Whether or not there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
		// @ts-ignore coercing `node` to a `Comment` causes TypeScript and Prettier to fight
		let mismatch = hydrating && is_promise(input) === (node.data === HYDRATION_START_ELSE);

		if (mismatch) {
			// Hydration mismatch: remove everything inside the anchor and start fresh
			set_hydrate_node(skip_nodes());
			set_hydrating(false);
		}

// ... (83 more lines)

Domain

Subdomains

Functions

Frequently Asked Questions

What does await.js do?
await.js is a source file in the svelte codebase, written in javascript. It belongs to the ClientRuntime domain, Hydration subdomain.
What functions are defined in await.js?
await.js defines 1 function(s): await_block.
What does await.js depend on?
await.js imports 26 module(s): Batch, BranchManager, async.js, batch.js, block, branches.js, capture, constants.js, and 18 more.
Where is await.js in the architecture?
await.js is located at packages/svelte/src/internal/client/dom/blocks/await.js (domain: ClientRuntime, subdomain: Hydration, directory: packages/svelte/src/internal/client/dom/blocks).

Analyze Your Own Codebase

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

Try Supermodel Free