Repository navigation
fix(dashboards): prevent horizontal filter bar from vanishing on cross-filter (#45050) - #45051
Conversation
CodeAnt PR Risk: Medium Risk
Assessed commit: |
…bar cross-filter interaction
…and default values
…nvironment compatibility
…t force-render by default
…Render with requiredFirst
ced2c42 to
012b11d
Compare
|
This PR addresses issue #45050 by resolving a reverse-portal DOM node contention issue in the horizontal filter bar. When a filter has The fix removes Whenever you have a moment, could you please take a look for review and merge? Thank you! |
| : undefined | ||
| } | ||
| forceRender={hasRequiredFirst} | ||
| ref={popoverRef} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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")?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Great point @sadpandajoe! Updated the real DropdownContainer regression test in commit f674ce81cb so that it:
- Starts with
dataMask: {}(no cross-filter chip in the initial state) and a real Redux store (createStore(..., reducerIndex)). - Forces overflow geometry via
getBoundingClientRect(450pxcontainer width,200pxper child) so the first two native filters (AccountandDate range) fit in the main row while the third (Flow) overflows and creates the closedMore filterspopover (dropdown-container-btn). - Verifies that while
More filtersis closed,dropdown-contentis not force-rendered into the DOM (re-adding forceRender={hasRequiredFirst} fails this assertion immediately). - Dispatches
updateDataMaskto add the cross-filter chip whileMore filtersis closed, then opensMore filtersand asserts all controls (Products Sold By Product Line,Account,Date range, andFlow) are reachable across the main row and opened popover.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Checking in on PR #45051 for issue #45050. The core contract is locked in by unit tests asserting that All unit and integration tests pass cleanly. Whenever you have a chance, please take a look for re-review. Thank you! @coderabbitai review |
…ore popover is closed (apache#45050)
|
Thanks for the review @sadpandajoe! I have pushed commit
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
requiredFirstenabled (and other filters such as Date range have a default value).Root Cause
In
FilterControls.tsx,hasRequiredFirstwas passed asforceRender={hasRequiredFirst}to<DropdownContainer>.DropdownContainerforwardsforceRenderto Ant Design's<Popover>.When
forceRenderistrue, 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, causingDropdownContainerto 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>inFilterControls.tsx. Closed overflow popovers should not force-render reverse portals in hidden DOM. Documented this constraint inDropdownContainerprops.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
npm test -- FilterControls.overflow.test.tsx.ADDITIONAL INFORMATION