Skip to content

fix(Popper): add null & connected checks for document#12284

Open
kmcfaul wants to merge 1 commit intopatternfly:mainfrom
kmcfaul:popper-document-nullcheck
Open

fix(Popper): add null & connected checks for document#12284
kmcfaul wants to merge 1 commit intopatternfly:mainfrom
kmcfaul:popper-document-nullcheck

Conversation

@kmcfaul
Copy link
Contributor

@kmcfaul kmcfaul commented Mar 23, 2026

What: Closes #12255

Adds a fallback to window.document for getDocumentElement.ts and adds isConnected checks for useIsomorphicLayoutEffect before createPopper is called.

@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

Walkthrough

Updated Popper utility system to add defensive checks: enhanced getDocumentElement with fallback handling for missing document references, and added isReferenceConnected helper to verify DOM element connectivity before Popper initialization.

Changes

Cohort / File(s) Summary
Popper DOM utilities and hooks
packages/react-core/src/helpers/Popper/thirdparty/popper-core/dom-utils/getDocumentElement.ts, packages/react-core/src/helpers/Popper/thirdparty/react-popper/usePopper.ts
Added fallback for missing document reference and new DOM connection check (isReferenceConnected) to prevent Popper initialization with detached elements.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding null checks for document in getDocumentElement and connected checks for elements in usePopper.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@patternfly-build
Copy link
Collaborator

patternfly-build commented Mar 23, 2026

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/react-core/src/helpers/Popper/thirdparty/react-popper/usePopper.ts (1)

128-130: Please add a regression test for detached→connected transitions.

Lines 128-130 correctly gate initialization on isConnected; adding a test for reconnection flow would lock in this behavior and prevent regressions.

If you want, I can draft the exact test cases for referenceElement and popperElement connectivity transitions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-core/src/helpers/Popper/thirdparty/react-popper/usePopper.ts`
around lines 128 - 130, Add a regression test for the detached→connected
transition that verifies usePopper initializes once elements reattach: mount a
component that uses usePopper with a referenceElement and popperElement
initially not connected (e.g., created but not appended to document), assert
that initialization does not run while isReferenceConnected(referenceElement) or
popperElement.isConnected are false, then append both elements to document (or
reattach the reference) and assert the hook creates/initializes the popper (spy
or assert popperInstance/instance creation or that the popper update method was
called). Target the usePopper hook and the gating checks isReferenceConnected,
referenceElement, and popperElement to ensure the reconnection flow is covered
and prevents regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/react-core/src/helpers/Popper/thirdparty/react-popper/usePopper.ts`:
- Around line 128-130: Add a regression test for the detached→connected
transition that verifies usePopper initializes once elements reattach: mount a
component that uses usePopper with a referenceElement and popperElement
initially not connected (e.g., created but not appended to document), assert
that initialization does not run while isReferenceConnected(referenceElement) or
popperElement.isConnected are false, then append both elements to document (or
reattach the reference) and assert the hook creates/initializes the popper (spy
or assert popperInstance/instance creation or that the popper update method was
called). Target the usePopper hook and the gating checks isReferenceConnected,
referenceElement, and popperElement to ensure the reconnection flow is covered
and prevents regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e3de51a5-434e-4d7a-8da2-2302dc4e4f66

📥 Commits

Reviewing files that changed from the base of the PR and between 641c888 and 316ffdc.

📒 Files selected for processing (2)
  • packages/react-core/src/helpers/Popper/thirdparty/popper-core/dom-utils/getDocumentElement.ts
  • packages/react-core/src/helpers/Popper/thirdparty/react-popper/usePopper.ts

logonoff added a commit to logonoff/openshift-console that referenced this pull request Mar 23, 2026
logonoff added a commit to logonoff/openshift-console that referenced this pull request Mar 23, 2026
Copy link
Contributor

@dlabaj dlabaj left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Bug - Popper - Cannot read properties of undefined (reading 'documentElement')

3 participants