Skip to content

fix(manipulation): connect sibling links in cloned selections - #5763

Open
xiaoyao-666-coder wants to merge 1 commit into
cheeriojs:mainfrom
xiaoyao-666-coder:fix/clone-sibling-links
Open

xiaoyao-666-coder wants to merge 1 commit into
cheeriojs:mainfrom
xiaoyao-666-coder:fix/clone-sibling-links

Conversation

@xiaoyao-666-coder

@xiaoyao-666-coder xiaoyao-666-coder commented Nov 16, 2026 •

Copy link
Copy Markdown

Cloning multiple nodes leaves their prev and next references null even though they share a synthetic document parent. For example, cloning three list items makes next() return an empty selection and :first-child match all three, while siblings() still sees the other items.

Use the existing DOM update helper when attaching clones to their document so sibling traversal and child selectors agree. Four regression cases cover HTML/XML traversal, selectors, removal of a middle clone, and text/comment links.

Fixes #5762.

Validation on Node.js 24.22.1:

  • All four new regression cases fail before the fix and pass afterward.
  • All 850 tests pass, including test type checking.
  • Full lint, TypeScript checking, package build, website build, and website type checking pass.
  • The pre-commit hook ran successfully.

AI assistance: reproduction, implementation, tests, and this description were prepared with Codex.

View guided diff

Use the DOM update helper for the synthetic clone document so sibling traversal and child selectors agree. Cover HTML/XML traversal, removal, and text/comment links.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T02:21:03.715100Z 93a76cb 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 Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Cloned elements now maintain correct parent-child and sibling relationships in HTML and XML modes, including after a clone is removed.
    • Cloned element, text, and comment nodes now report the correct previous and next sibling links.

clone now uses updateDOM to link cloned nodes. Regression tests check sibling traversal and child-position selectors in HTML and XML modes, including behavior after removing a clone.

Changes: Clone sibling links

Layer / File(s) Summary
Link cloned nodes and verify traversal
src/api/manipulation.ts, src/api/manipulation.spec.ts
clone calls updateDOM to link cloned nodes. Tests cover sibling traversal, child-position selectors, and sibling links for element, text, and comment nodes. They also verify removal behavior and that the source list remains unchanged.

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: fb55, plastic-time

Merge Risk: Minimal · up to 93a76

Cloned nodes now get consistent sibling links, so next(), prev() and child selectors behave correctly. The change is small and covered by regression tests. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (connecting prev/next sibling links for cloned nodes) and the affected area (manipulation, cloned selections). The raw summary confirms clone now links cloned nodes through `…
Description check Passed The description states the bug (cloned nodes keep null prev/next references under a shared synthetic parent), gives concrete examples (next(), :first-child, siblings()), names the fix (existing DOM up…
Linked Issues check Passed [#5762] requires consistent sibling traversal and positional child-selector results for clones that share a synthetic Document parent. The reviewed head changes clone() in src/api/manipulation.ts so t…
Out of Scope Changes check Passed The source change in src/api/manipulation.ts is a single-hunk replacement of a manual parent loop with the existing updateDOM helper, directly within the scope of #5762. The test changes in src/api/ma…
Full details: Title check

Explanation

The title names the fix (connecting prev/next sibling links for cloned nodes) and the affected area (manipulation, cloned selections). The raw summary confirms clone now links cloned nodes through updateDOM, and the spec file adds sibling-link tests. The title is specific and matches the main change.

Full details: Description check

Explanation

The description states the bug (cloned nodes keep null prev/next references under a shared synthetic parent), gives concrete examples (next(), :first-child, siblings()), names the fix (existing DOM update helper), lists regression cases that match the summarized spec changes, and references issue #5762. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

[#5762] requires consistent sibling traversal and positional child-selector results for clones that share a synthetic Document parent. The reviewed head changes clone() in src/api/manipulation.ts so that it calls updateDOM(clone, root) instead of only assigning each clone's parent. The update helper in src/parse.ts sets parent.children to the array, then sets prev and next on each node and sets node.parent. Clones from cloneNode have no parent, so the removal branch does not run. The result is that next(), prev(), and :first-child read the same links as the parent's children array. The PR summary reports four regression tests for HTML and XML traversal, child selectors, removal of a middle clone, and text/comment links. I did not read the spec file hunks directly, so the test results rest on the PR summary and the author's reported validation.

Full details: Out of Scope Changes check

Explanation

The source change in src/api/manipulation.ts is a single-hunk replacement of a manual parent loop with the existing updateDOM helper, directly within the scope of #5762. The test changes in src/api/manipulation.spec.ts (+42 lines) add regression cases for clone traversal, selectors, middle-clone removal, and text/comment links, which are the coverage items named in #5762. No unrelated files or behavior changes appear in the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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: 7a815974-5599-4901-bbcf-07609e132698
Commits

Reviewing files that changed from the base of the PR and between 6194a7f and 93a76cb.

Files selected for processing: 2

  • src/api/manipulation.spec.ts
  • src/api/manipulation.ts

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

@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 Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

clone() now uses updateDOM to connect cloned nodes beneath their synthetic document parent.

  • Cloned selections now keep their sibling links connected.

Reviews (1) · Last reviewed commit: "fix(manipulation): connect sibling links..." · 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

Development

Successfully merging this pull request may close these issues.

Cloned siblings have inconsistent traversal and child-selector results

1 participant