Skip to content

fix(Toolbar filter): Fixed null exception in Toolbar filter#12352

Open
tlabaj wants to merge 1 commit intopatternfly:mainfrom
tlabaj:toolbar_bug
Open

fix(Toolbar filter): Fixed null exception in Toolbar filter#12352
tlabaj wants to merge 1 commit intopatternfly:mainfrom
tlabaj:toolbar_bug

Conversation

@tlabaj
Copy link
Copy Markdown
Contributor

@tlabaj tlabaj commented Apr 10, 2026

What: Closes #12267

Summary

Fixes a crash in ToolbarFilter when label portal targets are missing or not yet mounted (#12267).

Changes

  • Collapsed listed filters: Portal only when labelGroupContentRef.current.firstElementChild resolves to a real node (fixes incorrect !== null checks vs undefined).
  • Toolbar content consumer: Use safe access for labelContainerRef so default / unset context does not throw on first render.

Tests

  • Added ToolbarFilter.test.tsx for default context and labelGroupContentRef.current === null while collapsed.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced ToolbarFilter robustness by improving how the component handles edge cases and null conditions during rendering across different states.
  • Tests

    • Added comprehensive test coverage for ToolbarFilter to ensure the component renders correctly in edge cases, including when nested contexts are unavailable or when certain internal conditions are null.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a579be7f-837a-43f3-ae7f-599710481ba6

📥 Commits

Reviewing files that changed from the base of the PR and between 911223a and 6a6d106.

📒 Files selected for processing (2)
  • packages/react-core/src/components/Toolbar/ToolbarFilter.tsx
  • packages/react-core/src/components/Toolbar/__tests__/ToolbarFilter.test.tsx

Walkthrough

This PR fixes a null reference regression in ToolbarFilter by adding null-safety checks to portal target derivations in both collapsed and expanded rendering states, and includes test coverage for edge cases where refs may be null.

Changes

Cohort / File(s) Summary
ToolbarFilter Portal Null-Safety
packages/react-core/src/components/Toolbar/ToolbarFilter.tsx
Refactored portal rendering logic to safely handle null refs using optional chaining and null coalescing operators. In collapsed state, collapsedLabelPortalTarget is computed with firstElementChild ?? null check. In expanded state, labelContainer is derived before portal creation, with portal render depending on labelContainer != null.
ToolbarFilter Tests
packages/react-core/src/components/Toolbar/__tests__/ToolbarFilter.test.tsx
Added new test suite with two test cases: (1) verifies ToolbarFilter renders without error when not nested under Toolbar/ToolbarContent, (2) verifies ToolbarFilter handles null labelGroupContentRef.current in collapsed state without throwing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change - fixing a null exception in Toolbar filter, which matches the primary objective.
Linked Issues check ✅ Passed The PR successfully addresses the regression in #12267 by implementing safe null checks for portal targets and conditional rendering in ToolbarFilter.
Out of Scope Changes check ✅ Passed All changes directly address the null dereference issue in ToolbarFilter with refactored portal logic and comprehensive test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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
Copy Markdown
Collaborator

patternfly-build commented Apr 10, 2026

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.

Regression - [ToolbarFilter] - [chipGroupContentRef.current is null] #10857

2 participants