Home / Function/ set_attributes() — svelte Function Reference

set_attributes() — svelte Function Reference

Architecture documentation for the set_attributes() function in attributes.js from the svelte codebase.

Entity Profile

Dependency Diagram

graph TD
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba["set_attributes()"]
  0acd2537_e1bf_d7ae_30d5_407378cfa4d3["attributes.js"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|defined in| 0acd2537_e1bf_d7ae_30d5_407378cfa4d3
  9a87a496_4e7d_9214_8bba_7bb2e3e47939["attribute_effect()"]
  9a87a496_4e7d_9214_8bba_7bb2e3e47939 -->|calls| 4c70ef10_16f1_40f4_1d51_8a7169bd1dba
  12da86e1_c608_1c76_660b_570e483dc67a["remove_input_defaults()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| 12da86e1_c608_1c76_660b_570e483dc67a
  318223ca_87d5_a1fe_45e4_c1304dea610b["get_attributes()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| 318223ca_87d5_a1fe_45e4_c1304dea610b
  f5b61c69_d41c_bdb7_b931_5b8b3374332c["set_hydrating()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| f5b61c69_d41c_bdb7_b931_5b8b3374332c
  cb6da1e2_2fb4_545a_1bea_8d33e5942ef9["clsx()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| cb6da1e2_2fb4_545a_1bea_8d33e5942ef9
  f6ad037c_58b5_d12c_2b22_fa60302bf35f["set_class()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| f6ad037c_58b5_d12c_2b22_fa60302bf35f
  cdcce596_d5f9_cd9b_91b7_5b23f82ccf97["set_style()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| cdcce596_d5f9_cd9b_91b7_5b23f82ccf97
  1d3fa733_c8b9_7ca3_c600_2689a6e7c29d["get_setters()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| 1d3fa733_c8b9_7ca3_c600_2689a6e7c29d
  5605d535_663e_c67f_f365_389c8234aff5["can_delegate_event()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| 5605d535_663e_c67f_f365_389c8234aff5
  414b9ea2_b052_6759_fdfb_f4cabf75669c["is_capture_event()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| 414b9ea2_b052_6759_fdfb_f4cabf75669c
  12245a28_3cec_3119_faa7_968496e0db88["create_event()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| 12245a28_3cec_3119_faa7_968496e0db88
  2d5290be_7d59_5095_a533_c737cb75a0a4["delegate()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| 2d5290be_7d59_5095_a533_c737cb75a0a4
  a305388e_cd72_059e_c54e_36001ca30e0a["set_attribute()"]
  4c70ef10_16f1_40f4_1d51_8a7169bd1dba -->|calls| a305388e_cd72_059e_c54e_36001ca30e0a
  style 4c70ef10_16f1_40f4_1d51_8a7169bd1dba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/internal/client/dom/elements/attributes.js lines 275–479

function set_attributes(
	element,
	prev,
	next,
	css_hash,
	should_remove_defaults = false,
	skip_warning = false
) {
	if (hydrating && should_remove_defaults && element.tagName === 'INPUT') {
		var input = /** @type {HTMLInputElement} */ (element);
		var attribute = input.type === 'checkbox' ? 'defaultChecked' : 'defaultValue';

		if (!(attribute in next)) {
			remove_input_defaults(input);
		}
	}

	var attributes = get_attributes(element);

	var is_custom_element = attributes[IS_CUSTOM_ELEMENT];
	var preserve_attribute_case = !attributes[IS_HTML];

	// If we're hydrating but the custom element is from Svelte, and it already scaffolded,
	// then it might run block logic in hydration mode, which we have to prevent.
	let is_hydrating_custom_element = hydrating && is_custom_element;
	if (is_hydrating_custom_element) {
		set_hydrating(false);
	}

	var current = prev || {};
	var is_option_element = element.tagName === 'OPTION';

	for (var key in prev) {
		if (!(key in next)) {
			next[key] = null;
		}
	}

	if (next.class) {
		next.class = clsx(next.class);
	} else if (css_hash || next[CLASS]) {
		next.class = null; /* force call to set_class() */
	}

	if (next[STYLE]) {
		next.style ??= null; /* force call to set_style() */
	}

	var setters = get_setters(element);

	// since key is captured we use const
	for (const key in next) {
		// let instead of var because referenced in a closure
		let value = next[key];

		// Up here because we want to do this for the initial value, too, even if it's undefined,
		// and this wouldn't be reached in case of undefined because of the equality check below
		if (is_option_element && key === 'value' && value == null) {
			// The <option> element is a special case because removing the value attribute means
			// the value is set to the text content of the option element, and setting the value
			// to null or undefined means the value is set to the string "null" or "undefined".
			// To align with how we handle this case in non-spread-scenarios, this logic is needed.
			// There's a super-edge-case bug here that is left in in favor of smaller code size:
			// Because of the "set missing props to null" logic above, we can't differentiate
			// between a missing value and an explicitly set value of null or undefined. That means
			// that once set, the value attribute of an <option> element can't be removed. This is
			// a very rare edge case, and removing the attribute altogether isn't possible either
			// for the <option value={undefined}> case, so we're not losing any functionality here.
			// @ts-ignore
			element.value = element.__value = '';
			current[key] = value;
			continue;
		}

		if (key === 'class') {
			var is_html = element.namespaceURI === 'http://www.w3.org/1999/xhtml';
			set_class(element, is_html, value, css_hash, prev?.[CLASS], next[CLASS]);
			current[key] = value;
			current[CLASS] = next[CLASS];
			continue;
		}

Domain

Subdomains

Called By

Frequently Asked Questions

What does set_attributes() do?
set_attributes() is a function in the svelte codebase, defined in packages/svelte/src/internal/client/dom/elements/attributes.js.
Where is set_attributes() defined?
set_attributes() is defined in packages/svelte/src/internal/client/dom/elements/attributes.js at line 275.
What does set_attributes() call?
set_attributes() calls 15 function(s): autofocus, can_delegate_event, clsx, create_event, delegate, get_attributes, get_setters, is_capture_event, and 7 more.
What calls set_attributes()?
set_attributes() is called by 1 function(s): attribute_effect.

Analyze Your Own Codebase

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

Try Supermodel Free