Home / Function/ _mount() — svelte Function Reference

_mount() — svelte Function Reference

Architecture documentation for the _mount() function in render.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  95c17f0f_1042_263c_3de2_f8ab899408b0["_mount()"]
  deb813bb_c5d2_3dfd_2554_606359abaa83["render.js"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|defined in| deb813bb_c5d2_3dfd_2554_606359abaa83
  855d318b_fb8d_deea_1877_351d93513f13["mount()"]
  855d318b_fb8d_deea_1877_351d93513f13 -->|calls| 95c17f0f_1042_263c_3de2_f8ab899408b0
  e6912e2f_bd46_b7e4_ae8b_8a5955a81c03["hydrate()"]
  e6912e2f_bd46_b7e4_ae8b_8a5955a81c03 -->|calls| 95c17f0f_1042_263c_3de2_f8ab899408b0
  a413fb77_0391_6be3_509e_911e3ab4e488["init_operations()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| a413fb77_0391_6be3_509e_911e3ab4e488
  034eb538_8c9d_e943_ab91_3ef5cfad2ef9["is_passive_event()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| 034eb538_8c9d_e943_ab91_3ef5cfad2ef9
  a08b6cc5_af73_1be4_d02f_3113cf8a8305["get()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| a08b6cc5_af73_1be4_d02f_3113cf8a8305
  0448eaeb_2934_f939_a81e_5b59a8c48202["component_root()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| 0448eaeb_2934_f939_a81e_5b59a8c48202
  ec54e18a_a454_5d8c_9e00_7bc16e4f49c4["create_text()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| ec54e18a_a454_5d8c_9e00_7bc16e4f49c4
  ac6ca4c8_e45c_6b5d_c938_0865d22a126a["boundary()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| ac6ca4c8_e45c_6b5d_c938_0865d22a126a
  ea5280ff_3b87_42ee_3823_3570b76a5779["push()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| ea5280ff_3b87_42ee_3823_3570b76a5779
  e23e5c5c_05b1_afa5_e280_5c89012b55a7["assign_nodes()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| e23e5c5c_05b1_afa5_e280_5c89012b55a7
  5ec9c9f6_f767_0a42_fdd7_0cedb5a42d33["hydration_mismatch()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| 5ec9c9f6_f767_0a42_fdd7_0cedb5a42d33
  7114b424_5006_2886_1565_8d8123ef1ad8["pop()"]
  95c17f0f_1042_263c_3de2_f8ab899408b0 -->|calls| 7114b424_5006_2886_1565_8d8123ef1ad8
  style 95c17f0f_1042_263c_3de2_f8ab899408b0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/render.js lines 161–270

function _mount(Component, { target, anchor, props = {}, events, context, intro = true }) {
	init_operations();

	/** @type {Set<string>} */
	var registered_events = new Set();

	/** @param {Array<string>} events */
	var event_handle = (events) => {
		for (var i = 0; i < events.length; i++) {
			var event_name = events[i];

			if (registered_events.has(event_name)) continue;
			registered_events.add(event_name);

			var passive = is_passive_event(event_name);

			// Add the event listener to both the container and the document.
			// The container listener ensures we catch events from within in case
			// the outer content stops propagation of the event.
			target.addEventListener(event_name, handle_event_propagation, { passive });

			var n = document_listeners.get(event_name);

			if (n === undefined) {
				// The document listener ensures we catch events that originate from elements that were
				// manually moved outside of the container (e.g. via manual portals).
				document.addEventListener(event_name, handle_event_propagation, { passive });
				document_listeners.set(event_name, 1);
			} else {
				document_listeners.set(event_name, n + 1);
			}
		}
	};

	event_handle(array_from(all_registered_events));
	root_event_handles.add(event_handle);

	/** @type {Exports} */
	// @ts-expect-error will be defined because the render effect runs synchronously
	var component = undefined;

	var unmount = component_root(() => {
		var anchor_node = anchor ?? target.appendChild(create_text());

		boundary(
			/** @type {TemplateNode} */ (anchor_node),
			{
				pending: () => {}
			},
			(anchor_node) => {
				push({});
				var ctx = /** @type {ComponentContext} */ (component_context);
				if (context) ctx.c = context;

				if (events) {
					// We can't spread the object or else we'd lose the state proxy stuff, if it is one
					/** @type {any} */ (props).$$events = events;
				}

				if (hydrating) {
					assign_nodes(/** @type {TemplateNode} */ (anchor_node), null);
				}

				should_intro = intro;
				// @ts-expect-error the public typings are not what the actual function looks like
				component = Component(anchor_node, props) || {};
				should_intro = true;

				if (hydrating) {
					/** @type {Effect & { nodes: EffectNodes }} */ (active_effect).nodes.end = hydrate_node;

					if (
						hydrate_node === null ||
						hydrate_node.nodeType !== COMMENT_NODE ||
						/** @type {Comment} */ (hydrate_node).data !== HYDRATION_END
					) {
						w.hydration_mismatch();
						throw HYDRATION_ERROR;
					}
				}

Domain

Subdomains

Called By

Frequently Asked Questions

What does _mount() do?
_mount() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/render.js.
Where is _mount() defined?
_mount() is defined in packages/svelte/src/internal/client/render.js at line 161.
What does _mount() call?
_mount() calls 10 function(s): assign_nodes, boundary, component_root, create_text, get, hydration_mismatch, init_operations, is_passive_event, and 2 more.
What calls _mount()?
_mount() is called by 2 function(s): hydrate, mount.

Analyze Your Own Codebase

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

Try Supermodel Free