Skip to content

persist data viewer scroll position across reloads - #17887

Merged
kevinushey merged 1 commit into
mainfrom
feature/data-viewer-scroll-persist
Jun 6, 2026
Merged

kevinushey merged 1 commit into
mainfrom
feature/data-viewer-scroll-persist

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

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. This extends that persisted state to include the scroll position, so reopening a data set returns you to where you were scrolled rather than the top.

What changed

src/cpp/session/resources/grid/DataViewer.js:

  • saveState() 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). Also guards against saving before the grid is initialized.
  • applySavedState() seeds the existing activeScrollRestore slot from the saved scroll. The restore then flows through restoreScrollAfterRefresh after the first row fetch, which re-checks the row count and defers to any live refresh-driven capture. Only runs once the column fingerprint matches.
  • onScrollEnd / onDeactivate 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 (host-side clear + onDismiss).

STATE_VERSION is intentionally left at 3 -- adding an optional field is backward-compatible, and bumping would have discarded users' existing pins/sorts/filters for a purely additive change.

Testing

Added an e2e test (scroll position is restored after a reload) that scrolls down, confirms the offset persisted to the shared host/iframe localStorage, reloads the data viewer iframe, and asserts the position is restored. The full data-viewer Playwright suite (19 tests) passes locally with no regressions.

Follow-on to the data viewer state-persistence work in #17861 and #17886.

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.
@kevinushey kevinushey added this to the Blue Plumbago milestone Jun 6, 2026
@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
320 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 dcad3806126e67af0740e724ca90fbccd29a5358 · Run #115

@kevinushey
kevinushey merged commit a31e68a into main Jun 6, 2026
10 checks passed
@kevinushey
kevinushey deleted the feature/data-viewer-scroll-persist branch June 6, 2026 15:26
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.

1 participant