Skip to content

Support CloneIndependentRoot feature#3170

Merged
JiuqingSong merged 2 commits into
masterfrom
u/jisong/cloneindependentroot
Oct 2, 2025
Merged

Support CloneIndependentRoot feature#3170
JiuqingSong merged 2 commits into
masterfrom
u/jisong/cloneindependentroot

Conversation

@JiuqingSong

Copy link
Copy Markdown
Collaborator

Today when we extract HTML from editor using ExportHTMLFast feature, we first clone a DOM tree, then pass it to plugins to do clean up. However, if plugin wants to set src of image, it will trigger an image downloading service call. This is a browser behavior.

In this change, I create a new experimental feature CloneIndependentRoot, when set, we will create an independent HTML document using document.implementation.createHTMLDocument(), then call importNode() to clone the DOM tree, this makes the cloned tree to be under this independent document context, so setting src of IMG won't really download it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces the CloneIndependentRoot experimental feature to prevent network requests when cloning DOM elements during HTML export. When enabled, the feature creates an independent HTML document context for cloned elements, avoiding browser behavior that would trigger image downloads when setting src attributes.

Key changes:

  • Added CloneIndependentRoot experimental feature flag
  • Modified DOM cloning logic to use independent document when feature is enabled
  • Added comprehensive test coverage for the new cloning behavior

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/roosterjs-content-model-types/lib/editor/ExperimentalFeature.ts Added CloneIndependentRoot feature flag definition
packages/roosterjs-content-model-core/lib/editor/core/DOMHelperImpl.ts Implemented independent document cloning logic and updated constructor
packages/roosterjs-content-model-core/lib/editor/core/createEditorCore.ts Integrated feature flag with DOMHelper creation
packages/roosterjs-content-model-core/test/editor/core/DOMHelperImplTest.ts Added test coverage for independent root cloning
demo/scripts/controlsV2/sidePane/editorOptions/ExperimentalFeatures.tsx Added UI control for the new feature
demo/scripts/controlsV2/sidePane/editorOptions/EditorOptionsPlugin.ts Enabled feature in demo configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@JiuqingSong
JiuqingSong merged commit 2ce5311 into master Oct 2, 2025
7 checks passed
@JiuqingSong
JiuqingSong deleted the u/jisong/cloneindependentroot branch October 2, 2025 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants