perf: carry the sibling anchor instead of rescanning per child #30
Openletstri(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/30/headopened tannerlinsley requested changes
- packages/redact/src/dom/reconcile.ts line 632OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -629,9 +620,13 @@629- domParent: Node,630- anchor: Node | null,631- skipAnchors: boolean,632-): void {620+function renderChildChain(parent: Fiber, domParent: Node, anchor: Node | null): void {621+ // The first DOM node a later sibling owns holds until that sibling renders,622+ // so it is cached instead of rescanned for every child — the rescan is O(n²)623+ // on long lists. Anything moving DOM in this parent mid-render (an inline624+ // portal move, a nested flushSync, an immediate insert outside a commit)625+ // leaves that node somewhere other than where this chain left it, and the626+ // next child rescans.627+ let cached: Node | null = null628+ let owner = parent.child629+ let placed: Node | null = null630+633631 for (let f = parent.child; f; f = f.sibling) {634- let nextAnchor = anchor635- if (!skipAnchors) {636- for (let sibling = f.sibling; sibling; sibling = sibling.sibling) {637- const dom = firstDomNode(sibling, domParent)632+ if (f === owner || (cached && (cached.previousSibling !== placed || !cached.parentNode))) {
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
64b7f0e0-e493-4b30-97bd-51040a02976e📥 Commits
Reviewing files that changed from the base of the PR and between 269c2250d81057b2e1dffbabb6f35126746e855e and c901f077d3c6409d7a1775f8036225f23cf20c70.
📒 Files selected for processing (2)
packages/redact/src/dom/reconcile.tstests/null-sibling-anchors.test.tsx🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Walkthrough#
renderChildChainnow caches a later sibling’s DOM anchor during child reconciliation. It rescans when the cached node changes, moves, or disconnects. A regression test covers movement to another parent, and the changeset records benchmark results.Changes#
Child Chain Anchor Optimization
packages/redact/src/dom/reconcile.ts,tests/null-sibling-anchors.test.tsx,.changeset/child-chain-anchors.mdrenderChildChainrescans when the cached anchor is invalid or belongs to another parent. The test covers anchor movement, and the changeset records the patch release and benchmark results.Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Merge Risk: ⚪ Minimal · up to
c901fNo actionable merge risk remains.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
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