Skip to content

data viewer: don't corrupt grid state while the tab is hidden - #18223

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/dataviewer-activate-redraw
Jul 14, 2026
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/dataviewer-activate-redraw

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

Investigating #18215 (data viewer blank after switching tabs and back) turned up a family of defects in how the vanilla-JS grid handles running while its tab is hidden. A hidden tab's iframe has no layout, so the grid viewport reads clientWidth/clientHeight/scrollTop/scrollLeft as 0, and grid code running in that state corrupted live state in ways the next activation never healed:

  • computeColumnWindow collapsed the virtualized column window to a single edge column (the zero-width "never render an empty body" fallback), and window.onActivate rebuilt rows against the stale window without recomputing it -- the same class of gap data viewer: redraw column window on pane resize #18090 closed for onResize.
  • onScroll/onScrollEnd/onDeactivate folded the zeroed scroll reads into the lastScrollTop/lastScrollLeft mirrors, discarding the saved scroll position.
  • window.onActivate itself can run before the tab widget is shown (SourceColumn.onActivate activates the target before selecting its tab), with the same effects.

Changes

  • computeColumnWindow keeps the current window when the viewport has no layout.
  • onScroll/onScrollEnd/onDeactivate no longer fold zero-geometry scroll reads into the mirrors.
  • window.onActivate defers itself to the next animation frame while the tab has no layout (rAF is paused for render-throttled frames, so the retry runs once layout exists), and re-derives the column window from live geometry before re-rendering, like the scroll handlers and onResize do.

Testing

Two new Playwright tests replay the corrupting sequences (a scroll gesture's tail landing after the tab switch; an early onActivate on the hidden tab) and assert the grid returns to the saved position with real cells rendered. Both fail without the DataViewer.js changes (scroll position lost, grid rendered at the wrong column window) and pass with them, alongside the neighboring tab-return test.

Whether this is the whole story for the original report is unconfirmed -- the reporter's deterministic mtcars repro (no scrolling) doesn't fit these code paths, and a machine-specific rendering issue is still plausible there -- so this hardens everything found in that investigation without claiming to close it.

Addresses #18215.

While the data viewer tab is hidden its iframe has no layout: the grid
viewport reads clientWidth/clientHeight/scrollTop/scrollLeft as 0. Grid
code running in that state could corrupt live state in ways the next
tab activation never healed:

- computeColumnWindow collapsed the virtualized column window to a
  single edge column (the zero-width fallback), and window.onActivate
  rebuilt rows against the stale window without recomputing it -- the
  same class of gap #18090 closed for onResize.
- onScroll/onScrollEnd/onDeactivate folded the zeroed scroll reads into
  the lastScrollTop/Left mirrors, discarding the saved position.
- window.onActivate itself can run before the tab widget is shown
  (SourceColumn.onActivate activates the target before selecting its
  tab), with the same effects.

Guard all of these against a collapsed viewport: computeColumnWindow
and the scroll mirrors now ignore zero-geometry reads, and onActivate
defers itself to the next animation frame until layout exists, then
re-derives the column window from live geometry before re-rendering.

The new e2e tests fail without these changes: replaying a scroll tail
or an early onActivate into the hidden iframe loses the scroll position
and leaves the grid rendered at the wrong window on return.

Addresses #18215.
@kevinushey kevinushey added this to the 2026.08 (Yellow Yarrow) milestone Jul 14, 2026
@posit-snyk-bot

posit-snyk-bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
1364 0 57 3
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ desktop-linux 460 0 14 1
✅ desktop-windows 460 0 16 1
✅ server-linux 444 0 27 1
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

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


All platforms - commit 159972e9952dc5c7bf0b891d672f4f85e87f6ae8 - Run #181

@kevinushey
kevinushey merged commit a7ed3e5 into main Jul 14, 2026
1 check passed
@kevinushey
kevinushey deleted the bugfix/dataviewer-activate-redraw branch July 14, 2026 21:26
kevinushey added a commit that referenced this pull request Jul 15, 2026
…18233)

* skip empty arguments when scanning for package-library mutations (#18204)

Expressions with empty arguments (e.g. 'View(mtcars[1, ])') caused
.rs.exprMutatesPackageLibrary() to error at the console prompt, since
binding the empty symbol to a variable and evaluating it signals a
missing-argument error. Skip such arguments during recursion.

* opt the data viewer grid out of browser scroll anchoring (#18222)

The grid body and pinned pane are virtualized: scrolling replaces the
rendered row window and resizes the top spacer row. With scroll
anchoring enabled, Chromium adjusts scrollTop to compensate for that
content shift, undoing the user's scroll. Most visible on Windows,
where discrete mouse-wheel ticks are driven through Chromium's
smooth-scroll animation, so wheel scrolling over the table body got
stuck. Same fix the summary sidebar received in #17977.

Addresses #18221

* data viewer: don't corrupt grid state while the tab is hidden (#18223)

While the data viewer tab is hidden its iframe has no layout: the grid
viewport reads clientWidth/clientHeight/scrollTop/scrollLeft as 0. Grid
code running in that state could corrupt live state in ways the next
tab activation never healed:

- computeColumnWindow collapsed the virtualized column window to a
  single edge column (the zero-width fallback), and window.onActivate
  rebuilt rows against the stale window without recomputing it -- the
  same class of gap #18090 closed for onResize.
- onScroll/onScrollEnd/onDeactivate folded the zeroed scroll reads into
  the lastScrollTop/Left mirrors, discarding the saved position.
- window.onActivate itself can run before the tab widget is shown
  (SourceColumn.onActivate activates the target before selecting its
  tab), with the same effects.

Guard all of these against a collapsed viewport: computeColumnWindow
and the scroll mirrors now ignore zero-geometry reads, and onActivate
defers itself to the next animation frame until layout exists, then
re-derives the column window from live geometry before re-rendering.

The new e2e tests fail without these changes: replaying a scroll tail
or an early onActivate into the hidden iframe loses the scroll position
and leaves the grid rendered at the wrong window on return.

Addresses #18215.

* extra defense against failure introspecting expr
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.

2 participants