Conversation
Plotly resizes responsive figures from a window resize listener, but when a tab was shown quarto.js only dispatched slideenter, so figures drawn while their tab was hidden kept Plotly's default 700px width. Also dispatch a window resize event from fireSlideEnter(). Closes quarto-dev#14939 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
devmcp
marked this pull request as draft
September 23, 2026 16:38
Plotly waits 100ms before handling window resize, so figures drawn while their tab was hidden were briefly shown at Plotly's default size before resizing. Redraw them with Plotly.relayout as soon as the tab is shown, and make the test check the first painted frame. Refs quarto-dev#14939 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 23, 2026
devmcp
marked this pull request as ready for review
September 23, 2026 18:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses the width part of #4705: Plotly figures in a tab that is hidden on page load don't fill the tab when it's shown. The same problem was reported in #14939, which was closed as a duplicate of #4705.
It doesn't fix the table problem that #4705 is titled for, where text cells in a fixed-size
go.Tablestay blank in a hidden tab, so #4705 should stay open. In my testing, re-rendering fixed-size figures withPlotly.react(figure, figure.data, figure.layout)when their tab is shown fills in the blank cells, but I've left that out to keep this PR focused.Plotly figures in a tab that is hidden on page load are drawn while their container has no size, so they fall back to Plotly's default size of 700×450px. Nothing redraws them when the tab is shown:
quarto.jsonly dispatchesslideenter(for htmlwidgets).This PR changes
src/resources/formats/html/quarto.jsso that when a tab is shown (Bootstrap'sshown.bs.tabor tabby'stabbyevent):Plotly.relayout(figure, { autosize: true }), so they're already the right size in the first frame the browser paints. Figures with a fixedwidthandheightare skipped.windowresizeevent is also dispatched, for other libraries that resize when the window does.The Plotly-specific redraw is needed because Plotly's own
resizehandler waits 100ms before redrawing. Relying on theresizeevent alone shows the figure at the wrong size for a few frames before it jumps to the right size.quarto.jsalready has library-specific handling here (slideenterfor htmlwidgets, jQuery events for Shiny), so I've followed that pattern. IfPlotlyisn't available as a global, figures still reach the right size through theresizeevent, just slightly later.Notes:
config={"responsive": False}are now also sized to fit the tab when it's shown, as they would have been if drawn while visible. They still don't follow later window resizes.slideenterhandling. I checked that they behave the same with this change (R plotly 4.12.1).fireSlideEnter()insrc/resources/formats/revealjs/plugins/support/support.js. I've left it unchanged to keep this PR focused.Tests
tests/docs/playwright/html/tabsets/plotly-tabsets.qmd, plus a Playwright test inhtml-tabsets.spec.ts. The test clicks the initially hidden tab and measures the Plotly figure in the first animation frame after the click, before the browser paints, checking that it's as wide as its container.resizeevent, because of the delayed redraw. With this PR it passes in Chromium, Firefox and WebKit (10 repeats each with--workers=1).theme: none) manually.html-search-tabsets,html-themesanddashboard-hash-navigationspecs locally in all three browsers, and they pass. Two dashboard tests fail intermittently on my machine when run in parallel, at the same rate with and without this change.Checklist
I have (if applicable):
AI-assisted PR