Home / Function/ swapHeadElements() — astro Function Reference

swapHeadElements() — astro Function Reference

Architecture documentation for the swapHeadElements() function in swap-functions.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  0722731f_183d_e797_27e9_3e58fdf1d7de["swapHeadElements()"]
  12084e8e_15f3_27ac_8f8b_d442375ff33d["swap-functions.ts"]
  0722731f_183d_e797_27e9_3e58fdf1d7de -->|defined in| 12084e8e_15f3_27ac_8f8b_d442375ff33d
  af9df8a2_d80a_7f14_9281_908d8b85f14f["swap()"]
  af9df8a2_d80a_7f14_9281_908d8b85f14f -->|calls| 0722731f_183d_e797_27e9_3e58fdf1d7de
  a6c8ec10_528f_0d13_d591_45ce3d9d7bd4["persistedHeadElement()"]
  0722731f_183d_e797_27e9_3e58fdf1d7de -->|calls| a6c8ec10_528f_0d13_d591_45ce3d9d7bd4
  style 0722731f_183d_e797_27e9_3e58fdf1d7de fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/transitions/swap-functions.ts lines 56–71

export function swapHeadElements(doc: Document) {
	for (const el of Array.from(document.head.children)) {
		const newEl = persistedHeadElement(el as HTMLElement, doc);
		// If the element exists in the document already, remove it
		// from the new document and leave the current node alone
		if (newEl) {
			newEl.remove();
		} else {
			// Otherwise remove the element in the head. It doesn't exist in the new page.
			el.remove();
		}
	}

	// Everything left in the new head is new, append it all.
	document.head.append(...doc.head.children);
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does swapHeadElements() do?
swapHeadElements() is a function in the astro codebase, defined in packages/astro/src/transitions/swap-functions.ts.
Where is swapHeadElements() defined?
swapHeadElements() is defined in packages/astro/src/transitions/swap-functions.ts at line 56.
What does swapHeadElements() call?
swapHeadElements() calls 1 function(s): persistedHeadElement.
What calls swapHeadElements()?
swapHeadElements() is called by 1 function(s): swap.

Analyze Your Own Codebase

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

Try Supermodel Free