Repository navigation
fix(dom): return null from getRoot while disconnected - #2597
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the disconnected-node handling changes.
No open issues 🎉
What changed in this PR
This PR makes the shared getRoot utility return null for disconnected nodes, preventing detached-component errors while preserving callers that need raw root-node identity.
Changes:
- Updates root API callers to handle disconnected nodes safely.
- Skips virtual-scroll stylesheet adoption while detached, relying on connection to adopt it.
- Adds a detach/reattach regression test and updates the specification and changelog.
| File | Description |
|---|---|
src/internals/utils/dom.ts |
Returns nullable roots and handles them in lookup and focus helpers. |
src/internals/directives/drag.ts |
Guards hit testing when the target is disconnected. |
src/internals/controllers/roving-focus.ts |
Handles a missing root during active-element lookup. |
src/internals/controllers/group.ts |
Preserves group scope identity with getRootNode(). |
src/internals/bases/alert.ts |
Preserves raw root comparisons for anchoring. |
src/components/virtualization/virtualization.ts |
Skips stylesheet adoption while disconnected. |
src/components/virtualization/virtualization.spec.ts |
Tests detached updates and styling after reattachment. |
src/components/virtualization/spec.md |
Documents detached-update behavior and its test scenario. |
src/components/virtualization/recycle.ts |
Handles missing roots during focused-item lookup. |
src/components/stepper/stepper.ts |
Guards active-step lookup for disconnected steppers. |
src/components/radio/controller.ts |
Preserves radio group scopes with getRootNode(). |
src/components/popover/position/native.ts |
Keeps observing raw target roots. |
src/components/highlight/service.ts |
Uses the shared nullable-root helper for stylesheet scope. |
src/components/button/button-base.ts |
Removes the redundant connection guard from command-target lookup. |
CHANGELOG.md |
Records the detached virtual-scroll fix. |
Review effort: Balanced
rkaraivanov
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
getRootcastgetRootNode()toDocument | ShadowRoot, but the root of a disconnected node is the node itself, a detached ancestor or a fragment. The cast hid that from the compiler: a property change on a detached virtual scroll threw, because the root had noadoptedStyleSheets, andgetElementByIdFromRootthrew for a detached button until #2592.getRootnow returnsnullwhile the node is disconnected. A connected node's root is always its document or a shadow root, also in another window, so the check needs no type test on the root. The callers that use the root's APIs handlenull:connectedCallbackinstead.getElementByIdFromRootreturnsnull, so the button no longer needs its ownisConnectedguard.getDeepActiveElementacceptsnulland usesdocument.activeElement.'adoptedStyleSheets' in rootcheck, whichgetRootnow covers.The alert, the group registry, the radio scope and the popover anchor observer only compare or observe roots, so they call
getRootNode()and keep their behavior for disconnected nodes.Type of Change
Testing
Virtual scroll spec: a property change while detached, then attached again. It fails on
masterwithCannot read properties of undefined (reading 'includes').Checklist
CHANGELOG.mdentry under[Unreleased]🤖 Generated with Claude Code