Repository navigation
Fix blurry inline notebook plots on HiDPI displays - #17100
Merged
Merged
Conversation
When custom figure dimensions (e.g. fig-width, fig-height, fig-asp) were specified, the device pixel ratio was not applied to the plot DPI, resulting in low-resolution images on HiDPI/Retina displays. This was a regression from 98bc020, which moved the DPI scaling inside a conditional that only applied to automatic (pixel-based) sizing. Move the DPI scaling back outside the conditional so it applies regardless of sizing mode. Addresses #16838.
Contributor
✅ 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. |
7 tasks
gtritchie
added a commit
that referenced
this pull request
Feb 28, 2026
- Fix TOCTOU race in buildCspHeader by loading atomic port into a local variable instead of reading it twice - Fix thread-unsafe caching in loadCspDirectives by using a C++11 static-initialized lambda instead of a manual bool guard - Add WLOG calls for file read, JSON parse, and schema errors in loadCspDirectives so failures are no longer silently swallowed - Add DLOG calls in injectThemeInfo when expected HTML tags are missing - Replace magic number with constexpr + strlen for class attribute offset - Fix inaccurate @return doc on handleAIChatRequest - Fix incomplete doc on setChatBackendPort (also called on stop) - Remove redundant inline comments covered by function-level docs Addresses #17100.
jcheng5
pushed a commit
that referenced
this pull request
Feb 28, 2026
* Add CSP headers and meta-tag theme injection for AI chat pane RStudio serves the chat UI HTML directly via rsession, bypassing the databot Express server's CSP middleware. Add CSP header support to the static file handler so the browser enforces Content-Security-Policy in RStudio mode. CSP directives are read from dist/csp.json (emitted by the databot build) so the policy stays in sync without hardcoding values in C++. The only RStudio-specific augmentation is adding the WebSocket origin to connect-src in desktop mode. Replace the inline <script> theme injection with a <meta> tag carrying theme colors as data attributes plus a class="dark" on the <html> tag. This avoids needing a CSP nonce for inline scripts. * Use existing string_utils::htmlEscape for attribute escaping Replace the local htmlEscapeAttr() with the existing string_utils::htmlEscape(str, isAttributeValue=true) from core/StringUtils, which handles the same characters plus carriage returns and newlines. * Fix thread safety, add logging, and improve docs in CSP code - Fix TOCTOU race in buildCspHeader by loading atomic port into a local variable instead of reading it twice - Fix thread-unsafe caching in loadCspDirectives by using a C++11 static-initialized lambda instead of a manual bool guard - Add WLOG calls for file read, JSON parse, and schema errors in loadCspDirectives so failures are no longer silently swallowed - Add DLOG calls in injectThemeInfo when expected HTML tags are missing - Replace magic number with constexpr + strlen for class attribute offset - Fix inaccurate @return doc on handleAIChatRequest - Fix incomplete doc on setChatBackendPort (also called on stop) - Remove redundant inline comments covered by function-level docs Addresses #17100. * Address PR review feedback on CSP and theme injection - Restrict theme injection to index.html only (not all HTML files) - Cache built CSP header string with mutex; rebuild only on port change - Fix port comparison to use >= 0 (port 0 is valid; sentinel is -1) - Add frame-ancestors 'self' to prevent clickjacking - Add kChatBackendPortNone sentinel constant, replace magic -1 - Remove unused getChatBackendPort() - Consolidate meta tag format to single raw string - Clarify HTML parsing comment about Vite output constraints
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.
Intent
Addresses #16838.
Summary
fig-width,fig-height,fig-asp) were blurry on HiDPI/Retina displaysdpi * pixelRatioscaling outside theunits == "px"conditional so it applies to both sizing modesDetails
Commit
98bc0203b5("support custom DPI in chunk plots") refactoredNotebookPlots.Rand inadvertently moved the DPI pixel-ratio scaling inside a conditional block that only executes for automatic sizing. Previously, DPI was unconditionally scaled viares = 96 * pixelRatio.When a user specifies custom figure dimensions, the sizing mode is set to
PlotSizeManualwithunits = "in", which skipped the pixel ratio multiplication on DPI. This produced images at 96 DPI instead of 192 DPI on 2x Retina displays (e.g., 672x480 instead of 1344x960 for a 7x5 inch plot).Test plan
fig-width/fig-height— verify the plot is equally crispfig-aspset — verify the plot is crisp