MCPcopy
hub / github.com/sveltejs/svelte / html

Function html

packages/svelte/src/internal/client/dom/blocks/html.js:51–160  ·  view source on GitHub ↗
(
	node,
	get_value,
	is_controlled = false,
	svg = false,
	mathml = false,
	skip_warning = false
)

Source from the content-addressed store, hash-verified

49 * @returns {void}
50 */
51export function html(
52 node,
53 get_value,
54 is_controlled = false,
55 svg = false,
56 mathml = false,
57 skip_warning = false
58) {
59 var anchor = node;
60
61 /** @type {string | TrustedHTML} */
62 var value = '';
63
64 if (is_controlled) {
65 var parent_node = /** @type {Element} */ (node);
66
67 if (hydrating) {
68 anchor = set_hydrate_node(get_first_child(parent_node));
69 }
70 }
71
72 template_effect(() => {
73 var effect = /** @type {Effect} */ (active_effect);
74
75 if (value === (value = get_value() ?? '')) {
76 if (hydrating) hydrate_next();
77 return;
78 }
79
80 if (is_controlled && !hydrating) {
81 // When @html is the only child, use innerHTML directly.
82 // This also handles contenteditable, where the user may delete the anchor comment.
83 effect.nodes = null;
84 parent_node.innerHTML = /** @type {string} */ (value);
85
86 if (value !== '') {
87 assign_nodes(
88 /** @type {TemplateNode} */ (get_first_child(parent_node)),
89 /** @type {TemplateNode} */ (parent_node.lastChild)
90 );
91 }
92
93 return;
94 }
95
96 if (effect.nodes !== null) {
97 remove_effect_dom(effect.nodes.start, /** @type {TemplateNode} */ (effect.nodes.end));
98 effect.nodes = null;
99 }
100
101 if (value === '') return;
102
103 if (hydrating) {
104 // We're deliberately not trying to repair mismatches between server and client,
105 // as it's costly and error-prone (and it's an edge case to have a mismatch anyway)
106 var hash = /** @type {Comment} */ (hydrate_node).data;
107
108 /** @type {TemplateNode | null} */

Callers

nothing calls this directly

Calls 10

set_hydrate_nodeFunction · 0.90
get_first_childFunction · 0.90
template_effectFunction · 0.90
hydrate_nextFunction · 0.90
assign_nodesFunction · 0.90
remove_effect_domFunction · 0.90
get_next_siblingFunction · 0.90
create_elementFunction · 0.90
get_valueFunction · 0.85
check_hashFunction · 0.85

Tested by

no test coverage detected