Lädt...

🔧 Build an offscreen DOM tree using this method.


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

I found the below code snippet in packages/scan/core/index.ts in react-scan source code.

const fragment = document.createDocumentFragment();

In this article, you will learn

  1. What is DocumentFragment?

  2. How is DocumentFragment used in react-scan?

  3. createDocumentFragment method.

What is DocumentFragment

The below information is picked from MDN docs.

Definition

The DocumentFragment interface represents a minimal document object that has no parent.

It is used as a lightweight version of Document that stores a segment of a document structure comprised of nodes just like a standard document. The key difference is due to the fact that the document fragment isn't part of the active document tree structure. Changes made to the fragment don't affect the document.

Usage

A common use for DocumentFragment is to create one, assemble a DOM subtree within it, then append or insert the fragment into the DOM using Node interface methods such as appendChild(), append(), or insertBefore(). Doing this moves the fragment's nodes into the DOM, leaving behind an empty DocumentFragment.

This interface is also of great use with Web components: <template> elements contain a DocumentFragment in their HTMLTemplateElement.content property.

An empty DocumentFragment can be created using the document.createDocumentFragment() method or the constructor.

Read more about DocumentFragment.

How is DocumentFragment used in react-scan?

I searched for DocumentFragment in the react-scan codebase and found the below shown results.

Image description

createDocumentFragment is used in two files:

  1. react-is-not-available.ts

  2. packages/scan/src/core/index.ts

createDocumentFragment method

Creates a new empty DocumentFragment into which DOM nodes can be added to build an offscreen DOM tree. Read more about createDocumentFragment.

About me:

Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.

I am open to work on interesting projects. Send me an email at [email protected]

My Github — https://github.com/ramu-narasinga

My website — https://ramunarasinga.com

My Youtube channel — https://www.youtube.com/@thinkthroo

Learning platform — https://thinkthroo.com

Codebase Architecture — https://app.thinkthroo.com/architecture

Best practices — https://app.thinkthroo.com/best-practices

Production-grade projects — https://app.thinkthroo.com/production-grade-projects

References:

  1. https://github.com/search?q=repo%3Aaidenybai%2Freact-scan%20DocumentFragment&type=code

  2. https://github.com/aidenybai/react-scan/blob/cd12e388f46a40293e6a276cd46dc3c6455246d7/packages/extension/src/inject/react-is-not-available.ts#L42

  3. https://github.com/aidenybai/react-scan/blob/cd12e388f46a40293e6a276cd46dc3c6455246d7/packages/scan/src/core/index.ts#L49

  4. https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment



...

🔧 Build an offscreen DOM tree using this method.


📈 69.34 Punkte
🔧 Programmierung

🔧 DOM and DOM Tree


📈 35.38 Punkte
🔧 Programmierung

🔧 Tree data structures in Rust with tree-ds (#2: Tree Operations)


📈 34 Punkte
🔧 Programmierung

🔧 Optimize Core Web Vitals - FCP and LCP: Lazy-Loading Offscreen &lt;iframe&gt; (2)


📈 28.59 Punkte
🔧 Programmierung

🕵️ CVE-2024-5693 | Mozilla Firefox up to 126 Offscreen Canvas cross-domain policy


📈 28.59 Punkte
🕵️ Sicherheitslücken

🎥 What’s new in Canvas — Offscreen Canvas and Text Metric use cases (Chrome Dev Summit 2019)


📈 28.59 Punkte
🎥 Video | Youtube

🔧 Automatically lazy-loading offscreen images &amp; iframes for Lite mode users


📈 28.59 Punkte
🔧 Programmierung

📰 Doom: Offscreen-Gameplay zeigt die Switch-Version in Aktion


📈 28.59 Punkte
📰 IT Nachrichten

🔧 Mythbusting DOM: Is DOM the same as HTML?


📈 24.05 Punkte
🔧 Programmierung

🔧 Mythbusting DOM: Was DOM Invented Alongside HTML?


📈 24.05 Punkte
🔧 Programmierung

🔧 Understanding Reconciliation in ReactJs - Keeping the Virtual DOM and the Real DOM in Sync.


📈 24.05 Punkte
🔧 Programmierung

🔧 ¿Qué es el Virtual DOM? Virtual DOM con manzanitas 🍎


📈 24.05 Punkte
🔧 Programmierung

🔧 Difference between a virtual DOM and a real DOM


📈 24.05 Punkte
🔧 Programmierung

🔧 Virtual DOM vs Direct DOM


📈 24.05 Punkte
🔧 Programmierung

🔧 Difference Between DOM and Virtual DOM


📈 24.05 Punkte
🔧 Programmierung

🔧 DOM Manipulation from Simple Updates to Virtual DOM


📈 24.05 Punkte
🔧 Programmierung

🔧 Understanding Refs and the DOM in React: Accessing and Manipulating DOM Elements


📈 24.05 Punkte
🔧 Programmierung

🕵️ Mozilla Firefox bis 46 DOM Element Handler mozilla::dom::Element Pufferüberlauf


📈 24.05 Punkte
🕵️ Sicherheitslücken

🔧 Virtual DOM and Actual DOM with Analogy Explanation


📈 24.05 Punkte
🔧 Programmierung

🕵️ Mozilla Firefox bis 46 DOM Element Handler mozilla::dom::Element Pufferüberlauf


📈 24.05 Punkte
🕵️ Sicherheitslücken

🔧 Virtual DOM and Actual DOM with Analogy Explanation


📈 24.05 Punkte
🔧 Programmierung

🔧 Dom and Virtual Dom


📈 24.05 Punkte
🔧 Programmierung

🔧 Actual DOM and Virtual DOM in Javascript


📈 24.05 Punkte
🔧 Programmierung

🔧 Real DOM vs Virtual DOM


📈 24.05 Punkte
🔧 Programmierung

🔧 DOM Manipulation: Selecting and Manipulating DOM Elements


📈 24.05 Punkte
🔧 Programmierung

🔧 Efficient DOM Manipulation with the Virtual DOM and Refs


📈 24.05 Punkte
🔧 Programmierung

🔧 Deciphering the Origins: Why the DOM is called the DOM?


📈 24.05 Punkte
🔧 Programmierung

🔧 Deciphering the Origins: Why the DOM is called the DOM?


📈 24.05 Punkte
🔧 Programmierung

🔧 Shadow DOM vs Virtual DOM: Understanding the Key Differences


📈 24.05 Punkte
🔧 Programmierung

🕵️ ammonia Crate up to 2.0.x on Rust HTML DOM Tree Recursion denial of service


📈 23.36 Punkte
🕵️ Sicherheitslücken

📰 Microsoft: Umbau am DOM-Tree beschleunigt Edge-Browser


📈 23.36 Punkte
📰 IT Nachrichten