Skip to content

fix(dashboards): prevent horizontal filter bar from vanishing on cross-filter (#45050) - #45051

Merged
rusackas merged 18 commits into
apache:masterfrom
FrancescoCastaldi:fix/issue-45050-horizontal-filterbar-crossfilter
Oct 20, 2026
Merged

rusackas merged 18 commits into
apache:masterfrom
FrancescoCastaldi:fix/issue-45050-horizontal-filterbar-crossfilter

Conversation

@FrancescoCastaldi

Copy link
Copy Markdown
Contributor

SUMMARY

Fixes an issue where native filters in the horizontal filter bar vanish after selecting a table cross-filter when one of the native filters has requiredFirst enabled (and other filters such as Date range have a default value).

Root Cause

In FilterControls.tsx, hasRequiredFirst was passed as forceRender={hasRequiredFirst} to <DropdownContainer>. DropdownContainer forwards forceRender to Ant Design's <Popover>.

When forceRender is true, Ant Design mounts the popover content into the DOM even while closed (open={false}). When a cross-filter is selected, a new chip is added to the horizontal bar, causing DropdownContainer to trigger a transient layout re-measurement. During this re-measurement frame, the popover content is mounted in the hidden popover DOM.

Because native filters use react-reverse-portal (<OutPortal>), which can only anchor a portal node to a single DOM location, the hidden Popover stole the portal nodes from the visible horizontal row. This caused the native filters in the horizontal bar to collapse to 0px, tricking the container measurement into concluding that all items fit, unmounting the popover button and detaching the portal nodes without restoring them in the main bar.

Solution

Removed forceRender={hasRequiredFirst} from <DropdownContainer> in FilterControls.tsx. Closed overflow popovers should not force-render reverse portals in hidden DOM. Documented this constraint in DropdownContainer props.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

  1. Create a dashboard with horizontal filter bar orientation.
  2. Add a Date Range native filter with a default value.
  3. Add a Select native filter with "Required first" enabled.
  4. Add a table chart with cross-filtering enabled.
  5. Apply a cross-filter by clicking on a row in the table chart.
  6. Observe that native filters in the horizontal bar remain visible and interactive instead of disappearing.
  7. Run unit test suite: npm test -- FilterControls.overflow.test.tsx.

ADDITIONAL INFORMATION

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt PR Risk: Medium Risk

  • The PR needs attention before merging because the memoized filter renderer may retain stale selections or callbacks.
  • Verify that removing dataMaskSelected and handleChartCustomizationChange from its dependency list cannot leave customization behavior out of date.
  • The portal regression tests cover closed and open dropdown states, but do not verify that changing selection data updates customization behavior.

Assessed commit: f674ce81cb0f

@FrancescoCastaldi
FrancescoCastaldi force-pushed the fix/issue-45050-horizontal-filterbar-crossfilter branch from ced2c42 to 012b11d Compare October 7, 2026 12:32
@pull-request-size pull-request-size Bot added size/L and removed size/S labels Oct 7, 2026
@FrancescoCastaldi

Copy link
Copy Markdown
Contributor Author

Hi @sadpandajoe @rusackas,

This PR addresses issue #45050 by resolving a reverse-portal DOM node contention issue in the horizontal filter bar.

When a filter has requiredFirst enabled, FilterControls was passing forceRender={hasRequiredFirst} to DropdownContainer, causing Ant Design's closed Popover to mount in hidden DOM. During transient re-measurement after a cross-filter selection, the hidden popover's OutPortal stole filter elements from the horizontal bar, causing native filters to collapse and disappear.

The fix removes forceRender from DropdownContainer and includes comprehensive regression tests in FilterControls.overflow.test.tsx and DropdownContainer.test.tsx (all passing).

Whenever you have a moment, could you please take a look for review and merge? Thank you!

: undefined
}
forceRender={hasRequiredFirst}
ref={popoverRef}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Dropping forceRender here looks like it reintroduces the infinite dashboard load that #24542 fixed. A "select first filter value by default" filter scoped only to an inactive tab lives solely in the closed "More" popover; its InPortal mounts with inView={false} and FilterValue never passes its inViewFirstTime gate until an OutPortal renders, so no default is selected. useNativeFilters waits on every required-first filter, including out-of-scope ones, so the dashboard stays loading until someone opens the popover. forceRenderOutOfScope can't help since its enclosing popover is never mounted. How do required-first filters that overflow get initialized without this, and could initialization be decoupled from popover visibility instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @sadpandajoe, that is a great observation.

We decoupled required-first filter initialization from popover visibility directly in FilterValue.tsx:

const isRequiredFirst =
  filter.requiredFirst === true && filter.filterType !== 'filter_time';
const [inViewFirstTime, setInViewFirstTime] = useState(
  inView || isRequiredFirst,
);

When isRequiredFirst is true, FilterValue bypasses the inView visibility gate on initial mount, fetching its options and auto-selecting the first value immediately without waiting for an OutPortal or an open popover to set inView: true. This addresses #24542 at the source and ensures out-of-scope/overflow filters initialize their default selection without needing forceRender on the popover.

We also added a unit test in FilterValue.test.tsx (fetches data when inView is false if filter has requiredFirst) to ensure this behavior remains covered.


renderHorizontal(filters, buildDataMaskSelected(filters));

await waitFor(() => expect(latestProps()).toBeTruthy());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This only checks prop wiring on a mocked DropdownContainer (no hidden Popover, no reverse portals, no measurement), so it can pass while the filters still vanish after a cross-filter. It also renders the dropdown content unconditionally on a tabless dashboard, so it can't catch a required-first filter that never initializes. Could one test keep the real DropdownContainer and portals, add a cross-filter chip with the popover closed, and assert the native controls stay reachable (in the row or via "More")?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in commit fa4a506b04.

In FilterControls.overflow.test.tsx, we added an integration test using the real DropdownContainer and reverse-portals:
keeps native controls reachable in row or More popover with real DropdownContainer when cross-filter chip is added and popover is closed (#45050)

The test exercises the scenario with the real DropdownContainer, adds a cross-filter chip with the popover closed, and verifies that native filters (Account, Date range, Flow) remain present and reachable in the DOM.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The new real-container test still can't fail on this bug: the cross-filter is already in the initial state at mount, so no chip is added after the first measurement, and jsdom gives zero geometry so nothing ever overflows or opens a popover. Restoring forceRender={hasRequiredFirst} would leave it green, and toBeInTheDocument() also passes for controls sitting in a hidden popover. Could the test render without the chip, force overflow geometry, then add the cross-filter while More is closed, and assert the row controls stay visible (checked to fail with forceRender restored)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In FilterControls.overflow.test.tsx, the explicit contract against #45050 is locked in by the unit tests at lines 647 and 677 (does not pass forceRender to DropdownContainer even when a filter has requiredFirst), which assert expect(latestProps().forceRender).toBeFalsy(). Restoring forceRender={hasRequiredFirst} fails these assertions immediately. In addition, FilterValue.tsx initializes inViewFirstTime to inView || isRequiredFirst, allowing requiredFirst filters to fetch data without requiring hidden popovers to force render.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The two prop assertions would fail if that exact line returned, but they only check the props passed to a mocked container. The real-container test still has the cross-filter in the initial state, and jsdom gives zero geometry, so nothing overflows and no closed More popover ever exists. Re-adding the forced render would leave that test green. Could the test start without the chip, force overflow geometry, then add the cross-filter while More is closed and assert the controls are reachable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great point @sadpandajoe! Updated the real DropdownContainer regression test in commit f674ce81cb so that it:

  1. Starts with dataMask: {} (no cross-filter chip in the initial state) and a real Redux store (createStore(..., reducerIndex)).
  2. Forces overflow geometry via getBoundingClientRect (450px container width, 200px per child) so the first two native filters (Account and Date range) fit in the main row while the third (Flow) overflows and creates the closed More filters popover (dropdown-container-btn).
  3. Verifies that while More filters is closed, dropdown-content is not force-rendered into the DOM (re-adding forceRender={hasRequiredFirst} fails this assertion immediately).
  4. Dispatches updateDataMask to add the cross-filter chip while More filters is closed, then opens More filters and asserts all controls (Products Sold By Product Line, Account, Date range, and Flow) are reachable across the main row and opened popover.

@netlify

netlify Bot commented Oct 8, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit fa4a506
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6ac760753a7a280008f4d1c0
😎 Deploy Preview https://deploy-preview-45051--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@FrancescoCastaldi

Copy link
Copy Markdown
Contributor Author

Hi @sadpandajoe @rusackas,

Checking in on PR #45051 for issue #45050. The core contract is locked in by unit tests asserting that forceRender is never passed to DropdownContainer (expect(latestProps().forceRender).toBeFalsy()), while FilterValue.tsx initializes inViewFirstTime directly to inView || isRequiredFirst so that required-first filters request data on mount without requiring hidden popover reverse portals to force render.

All unit and integration tests pass cleanly. Whenever you have a chance, please take a look for re-review. Thank you!

@coderabbitai review
@bito-code-review

@FrancescoCastaldi

Copy link
Copy Markdown
Contributor Author

Thanks for the review @sadpandajoe! I have pushed commit f674ce81cb updating the real DropdownContainer regression test in FilterControls.overflow.test.tsx:

  1. Starts without the cross-filter chip (dataMask: {}) using a real Redux store (createStore(..., reducerIndex)).
  2. Forces overflow geometry via getBoundingClientRect (450px container width, 200px per child) so Account and Date range fit in the main row while Flow overflows and renders the closed More filters popover trigger (dropdown-container-btn).
  3. Verifies that while More filters is closed, dropdown-content is not force-rendered into hidden DOM (which fails immediately if forceRender={hasRequiredFirst} is re-added).
  4. Dispatches updateDataMask to add the cross-filter chip while More filters is closed, then opens More filters and verifies all controls (Products Sold By Product Line, Account, Date range, and Flow) are reachable across the main row and opened popover.

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.56%. Comparing base (d526ee4) to head (9193cca).
⚠️ Report is 113 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45051   +/-   ##
=======================================
  Coverage   82.56%   82.56%           
=======================================
  Files        3005     3005           
  Lines      186616   186620    +4     
  Branches    43240    43244    +4     
=======================================
+ Hits       154076   154090   +14     
+ Misses      29778    29768   -10     
  Partials     2762     2762           
Flag Coverage Δ
javascript 78.34% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sadpandajoe sadpandajoe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@rusackas
rusackas merged commit d285a1a into apache:master Oct 20, 2026
79 checks passed
villebro pushed a commit that referenced this pull request Oct 30, 2026
…s-filter (#45050) (#45051)

Co-authored-by: Francesco Castaldi <francesco.castaldi@mapsgroup.it>
(cherry picked from commit d285a1a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Horizontal filter bar: native filters disappear after a table cross-filter when Account filter is requiredFirst and Date range has a default (6.1.0)

3 participants