Skip to content

fix(clone): preserve XML element types - #2032

Open
awais-ur-rehman wants to merge 1 commit into
fb55:masterfrom
awais-ur-rehman:feat/preserve-xml-clone-node-type
Open

awais-ur-rehman wants to merge 1 commit into
fb55:masterfrom
awais-ur-rehman:feat/preserve-xml-clone-node-type

Conversation

@awais-ur-rehman

@awais-ur-rehman awais-ur-rehman commented Oct 31, 2026 •

Copy link
Copy Markdown

Summary

Cloning an XML script or style element currently changes its type from tag to script or style. DomHandler deliberately creates these elements as ordinary tags in XML mode, but cloneNode reconstructs them without the original type and the Element constructor infers HTML-specific types from their names.

Pass the original type to the constructor. Parser-based regressions cover both element names, shallow clones, and deep document clones; the existing HTML clone tests continue to pass.

Testing

Validation on Node 24.13.0: both new cases fail before the change; npm test passes all 35 tests and the complete ESLint, TypeScript, and Biome checks. npm run build passes. Biome reports two existing configuration-migration notices; no configuration changes are included.

Breaking Changes

None.

Prepared and validated with OpenAI Codex assistance.

Manual verification: Parse a script or style element in XML mode and clone it; both the shallow element and deep tree clone should preserve ElementType.Tag.

View guided diff

Summary by CodeRabbit

  • Bug Fixes
    • Cloned XML script and style elements now retain their original element type. This keeps shallow-cloned elements correctly identified and ensures deep-cloned results match the source, improving consistency when working with these elements. XML parsing and cloning now preserve the distinction between regular tags, scripts, and styles.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T11:10:40.322857Z cadf1b9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a86fe4ea-5214-4e46-9c07-03a3760e059e
Commits

Reviewing files that changed from the base of the PR and between efb8d49 and cadf1b9.

Files selected for processing: 2
  • src/node.spec.ts
  • src/node.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

cloneNode now passes the source element’s type to the Element constructor. XML-mode tests cover parsing and cloning script and style elements.

Changes: Element clone type preservation

Layer / File(s) Summary
Preserve and test element type
src/node.ts, src/node.spec.ts
cloneNode passes the source element’s type to the constructor. XML-mode tests check that parsed script and style elements and their shallow clones have ElementType.Tag, and that a deep clone is strictly equal to the original.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: fb55

Merge Risk: Minimal · up to cadf1

No actionable merge-blocking risk is evident from the supplied change and tests.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving XML element types during cloning.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/node.spec.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

src/node.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each cloned tag,
Then hops through XML with a wag.
Script and style keep their type,
Deep copies match just right.
The bunny’s done; it guards the bag.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

View guided diff | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] This PR appears safe to merge.

Summary

cloneNode now preserves an element’s stored type instead of choosing it again from its name.

  • Cloned XML script and style elements keep their tag type.

Reviews (1) · Last reviewed commit: "fix: preserve element types when cloning" · Reviewed by Greptile

This branch has not been deployed

No deployments
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.

1 participant