Skip to content

fix data viewer remembering filters and sorts across close/reopen - #17886

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/17830-data-viewer-filter-state
Jun 6, 2026
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/17830-data-viewer-filter-state

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

The data viewer rewrite (#17382) persists per-object UI state (sorts, filters, pinned columns) to localStorage. This fixes two problems with how that state is restored and cleared, reported in #17830.

Saved state survived an explicit close

Closing a data viewer tab is supposed to discard its saved state, but it didn't: the clear ran inside the iframe via window.onDismiss, which is driven by TabClosedEvent -- and that fires after the tab widget (and its iframe) has already been detached from the DOM (DocTabLayoutPanel.remove calls super.remove before firing the event). So getWindow() was null and the in-frame clear silently no-oped, leaving the entry in localStorage. Reopening the data set then restored stale filters/sorts.

The close-vs-move distinction is only known post-detach (DISMISS_TYPE_CLOSE), so a pre-detach clear isn't an option. Instead, the iframe now reports its localStorage key on load (stateKeyCallback), and on an explicit close the host clears that key directly via shared same-origin localStorage -- which works even though the frame is gone. An explicit close is the only teardown that clears; a session suspend/restore or a page reload still preserves state (which is the intended behavior).

Restored filters were applied with no visible filter UI

Restoring a saved filter sent it to the server (the rows were filtered) but left the filter row hidden, so the filter was active with no visible UI to see or edit it. Bootstrap now reveals the filter row when restored filters are non-empty (recorded as a post-init action so it survives column pagination), and a new filterStateCallback keeps the toolbar funnel latch in sync -- mirroring the existing sidebarStateCallback.

Tests

Adds two Playwright regression tests to data_viewer.test.ts:

  • explicitly closing the viewer clears its saved sorts and filters -- sorts a column, confirms the saved-state key is readable from the host page (proving the host/iframe share localStorage), closes the tab, and asserts the key is gone.
  • restored filters reveal the filter row after a reload -- applies a filter, reloads the iframe, and asserts the filter row auto-reveals with its value, the toolbar funnel reports aria-pressed=true, and the data is still filtered.

All 18 tests in the file pass (16 existing + 2 new).

Fixes #17830

@kevinushey kevinushey added this to the Blue Plumbago milestone Jun 6, 2026
@kevinushey
kevinushey requested a review from gtritchie June 6, 2026 00:08
@gtritchie

Copy link
Copy Markdown
Member

Review Summary

Reviewed across general code quality, test coverage, error handling, and comment accuracy. No critical or blocking issues — the design holds up: the same-origin localStorage assumption, the close-vs-move gating, the host-side-clear ordering, and the dual-sync callback pattern all check out. One test gap is worth acting on.

Important

1. The close-vs-move distinction has zero test coverage. This is the central correctness invariant of the fix. DataEditingTarget.onDismiss only clears state on DISMISS_TYPE_CLOSE, deliberately not on a tab move between source columns. The new test exercises only the CLOSE branch. A future refactor that drops the dismissType guard (or clears unconditionally) would silently wipe a user's sorts/filters on every column move, and the suite would stay green. Worth a test that moves the tab and asserts state survives — or, if column-move is hard to drive in Playwright, a note that it's deliberately uncovered.

Suggestions

2. Suspend/restore preservation is asserted in NEWS but only approximated in tests. The reload test is a reasonable proxy, but actual session suspend/restore is a distinct teardown path (the tab widget is torn down and rebuilt) and is the behavior NEWS.md explicitly promises. Nice-to-have.

3. onDismiss failures are invisible in production. DataTable.onDismiss logs via Debug.logException, which is dev-console-only in release builds — so the now-primary host-side clear fails silently in production. The broad catch(Exception e) also now covers clearSavedStateHostSide. Impact is benign (worst case: stale localStorage) and it matches the sibling onDeactivate convention, so this is informational rather than required.

4. Silent un-cleared state if the iframe never finished loading before close. If the user opens and closes the viewer before the iframe load fires, stateKeyCallback never runs, stateKey_ stays null, clearSavedStateHostSide early-returns, and the in-frame clear no-ops. Negligible footprint (little/nothing was persisted that fast), but a one-line comment noting the early-return's dual meaning would help a future reader not mistake it for dead defensive code.

5. Minor: the diff shows spurious deletions. The branch is one commit behind main's HEAD, so the comparison surfaces unrelated deletions (code_suggestions.test.ts, etc.) from main's commit 30794c712f. A rebase would clean up the diff.

@gtritchie gtritchie 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! Mr. C has some ideas on additional tests, comment tweaks, etc.

@github-actions

github-actions Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

🍎 macOS Desktop E2E · ARM64

✅ All tests passed!

████████████████████ 100% pass rate

✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
319 0 9 1
📥 Download Playwright report

⬇️ playwright-report.zip — extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


2 shards · macos-26 ARM64 · commit 9138fab63198b6490d98ea7e9a20118fe9629f6f · Run #114

The data viewer rewrite persists per-object UI state (sorts, filters,
pins) to localStorage. Two problems with how that state is restored and
cleared:

- Explicitly closing a data viewer tab failed to clear the saved state,
  because the clear ran inside the iframe via onDismiss -- which fires
  from TabClosedEvent, after the tab widget (and its iframe) is already
  detached. getWindow() was null, so the in-frame clear silently no-oped
  and reopening the data set restored stale filters/sorts. The host now
  clears the saved-state key directly via shared same-origin localStorage
  (the iframe reports its key on load via stateKeyCallback), which works
  after the frame is gone. Close is the only teardown that clears; suspend
  /restore and page reload still preserve state.

- Restoring a saved filter applied it to the data but left the filter row
  hidden, so the filter was active with no visible UI. Bootstrap now
  reveals the filter row when restored filters are non-empty, and a new
  filterStateCallback keeps the toolbar funnel latch in sync.

Adds Playwright regression tests for both behaviors.
@kevinushey
kevinushey force-pushed the bugfix/17830-data-viewer-filter-state branch from 1603eec to 9138fab Compare June 6, 2026 05:27
@kevinushey
kevinushey merged commit 9708cff into main Jun 6, 2026
10 checks passed
@kevinushey
kevinushey deleted the bugfix/17830-data-viewer-filter-state branch June 6, 2026 06:21
kevinushey added a commit that referenced this pull request Jun 6, 2026
The data viewer already persists per-object UI state (pinned columns,
sorts, filters, sidebar visibility, column widths) to localStorage so it
survives a reload / suspend-restore, and clears it on an explicit close.
Extend that persisted state to include the scroll position.

saveState now records scroll: { top, left, rows }, keyed to the
unfiltered row count so a frame whose size changed while closed reopens
at the top (the same guard in-place refreshes use). applySavedState
seeds the existing activeScrollRestore slot from the saved scroll, so
the restore flows through restoreScrollAfterRefresh after the first row
fetch -- which re-checks the row count and defers to any live
refresh-driven capture. onScrollEnd and onDeactivate now call saveState
so the persisted position stays current.

Clearing on close needs no new code: scroll rides in the same
localStorage entry the close path already removes.

Follow-on to the data viewer state-persistence work in #17861 and #17886.
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.

Feature request: option to not remember Data Viewer filters and sorts when reopening

2 participants