Skip to content

Size the Skia web surface to the chart's painted box - #101291

Merged
roryabraham merged 3 commits into
Expensify:mainfrom
mukhrr:fix/95221
Sep 24, 2026
Merged

roryabraham merged 3 commits into
Expensify:mainfrom
mukhrr:fix/95221

Conversation

@mukhrr

@mukhrr mukhrr commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Chart text on web looks blurry: the Skia canvas is sized for the chart's design width, but a CSS transform paints it at a different size, so the browser resamples it. The web renderer now sizes the canvas to what is actually painted, and the inline chart waits for its column to be measured before mounting so that size is known when the surface is created.

Fixed Issues

$ #95221
PROPOSAL: #95221 (comment)

Tests

Precondition: a chat containing a chart message (an admins room summary), on a HiDPI screen.

  1. Open the chat with the chart and make the browser window narrower than the chart (about 1000px wide), so the chart is scaled down to fit the column.
  2. Compare the chart title with the message author name above it. Verify both are equally sharp, with no grey fringe around the chart letters.
  3. Widen the window so the chart is shown at its full width. Verify the chart still renders and looks the same as before.
  4. Hover the chart and click Expand.
  5. Compare the chart title in the expanded view with the "Details" header. Verify the chart text is as sharp as the header.
  6. Close the expanded view. Verify the inline chart renders normally.
  7. In DevTools, with the expanded view open, run [...document.querySelectorAll('canvas')].at(-1) and compare its width with Math.round(getBoundingClientRect().width * devicePixelRatio). Verify the two numbers are equal.
  • Verify that no errors appear in the JS console

Offline tests

Charts render from data already in the message, so the network state cannot affect this change. Run steps 1 to 6 while offline and verify the same results.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

Web-only change (the patched file is SkiaPictureView.web.js and native charts are not transform-scaled).

Android: mWeb Chrome after-inline after-modal android-modal-4x android-modal-100pct
iOS: Native

Web-only change (the patched file is SkiaPictureView.web.js and native charts are not transform-scaled).

iOS: mWeb Safari after-inline after-modal
MacOS: Chrome / Safari

Chart title inside the expand modal, 1440px window, before and after (4x crop of the same device pixels):

admins-modal-4x

Inline chart in the chat column, 1440px window, before and after:

admins-inline1440-4x full-modal-after

Charts are laid out at their authored design width and fitted to the chat
column or the expand modal with a CSS transform. react-native-skia sizes the
canvas backing store from clientWidth, which does not include that transform,
so the surface is rasterised for the design box and the browser resamples it
onto a differently sized area. Text inside the chart ends up softer than the
chat text next to it.

Patch the web renderer to derive the pixel ratio from the painted width over
the layout width, and mount the inline chart only after its column has been
measured, since the surface is created on the canvas's first layout and would
otherwise be sized before the transform is applied.
@mukhrr
mukhrr requested review from a team as code owners September 16, 2026 06:49
@melvin-bot
melvin-bot Bot requested review from abdulrahuman5196 and heyjennahay and removed request for a team September 16, 2026 06:49
@melvin-bot

melvin-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown

@abdulrahuman5196 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dd910841f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +22 to +23
+ const paintedWidth = canvas.getBoundingClientRect().width;
+ const ratio = canvas.clientWidth > 0 && paintedWidth > 0 ? this.pd * (paintedWidth / canvas.clientWidth) : this.pd;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute the surface after responsive scale changes

When the window, RHP, or modal is resized after the chart mounts, VictoryChartContainerResponsive updates only the ancestor's CSS transform while the canvas retains its fixed design-size clientWidth. Because this ratio is calculated only in Skia's canvas ResizeObserver callback, and CSS transform changes do not trigger that observer, this.ratio and the backing-store dimensions remain at their initial values and the browser resumes resampling the chart. The renderer needs to be explicitly resized or notified whenever the responsive scale changes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdulrahuman5196 i think makes sense. what do you think? i mean without a remount a narrow-then-wide resize leaves the surface upscaled, so i would add key={scale} back in both places, it is the only resize handling here. cost is very cheap, i think, it's a remount per layout tick while someone drags the window edge

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mukhrr looks good. kindly make the change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems we don't need it anymore. I merged main and already done good job there

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged main and already done good job there

I don't understand this, could you kindly explain

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean upstream main zoom rewrite renders it natively at the zoom-headroom size on a static bitmap and shows it minified until you zoom, so the old upscale blur is gone and we don't need key={scale} workaroundd

@abdulrahuman5196

Copy link
Copy Markdown
Contributor

Hi, will check on this tomorrow morning IST.

The Skia surface is sized from the painted box only when the canvas first
lays out, and a change to the fit transform never re-lays it out. Keying the
inline chart and the expanded chart on their scale re-creates the surface at
the new painted size after a resize, instead of leaving the browser to stretch
the old one.
# Conflicts:
#	src/components/HTMLEngineProvider/HTMLRenderers/VictoryChartRenderer/components/VictoryChartExpandModal.tsx
@abdulrahuman5196

Copy link
Copy Markdown
Contributor

@codex review

return (
<View
style={styles.mw100}
style={styles.w100}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we making the width changes? @mukhrr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the chart now mounts only after the container is measured. with mw100 the wrapper shrinks to its children, and there are no children yet at that point, so it measures 0 wide, containerWidth stays 0 and the chart never mounts. w100 makes it measure the column on its own.

@abdulrahuman5196

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
androidHybrid-0-Screen_Recording_2026-09-24_at_9.41.37.PM.mov
Android: mWeb Chrome
androidMWeb-0-Screen_Recording_2026-09-24_at_9.28.33.PM.mov
iOS: HybridApp
iosHybrid-0-Screen_Recording_2026-09-24_at_9.16.29.PM.mov
iOS: mWeb Safari
iosMWeb-0-Screen_Recording_2026-09-24_at_9.14.52.PM.mov
MacOS: Chrome / Safari
macOS-0-Screen_Recording_2026-09-24_at_8.54.46.PM.mov

@abdulrahuman5196 abdulrahuman5196 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good and works well. Reviewers checklist is also complete.

All yours. @roryabraham

🎀 👀 🎀
C+ Reviewed

@melvin-bot
melvin-bot Bot requested a review from roryabraham September 24, 2026 16:16
Untransformed canvases keep the previous ratio, so nothing else changes.
```

- Upstream PR/issue:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mukhrr Please create an upstream issue and PR for the patch. Any time you introduce a patch, it's implied that an upstream issue and PR, along with the upgrade to later remove the patch after the fix is merged upstream is in-scope.

Not going to block the bug fix on this, but the issue should stay open until this is done. Payment should be withheld at least until the issue/PR is created.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roryabraham thanks for great advice. Here is upstream issue and PR. Now do you think we should raise a mini expensify PR to include these in patch details?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for opening those! Yes, a PR to update details.md would be great, thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it is #102407
@roryabraham lets get it merged. thanks

@roryabraham
roryabraham merged commit c411b57 into Expensify:main Sep 24, 2026
42 of 53 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/roryabraham in version: 9.4.94-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site changes are needed for this PR, so I didn't create a docs PR.

This PR fixes blurry chart text on web. It sizes the Skia canvas to the size actually painted on screen, and it waits to mount the inline chart until its column width is measured. It doesn't add or rename any feature, setting, button, or step. Charts just look sharper.

What I checked
  • Changed files: a @shopify/react-native-skia web patch, VictoryChartContainerResponsive.tsx, and a unit test. None of them change copy or UI labels.
  • The only help article about Concierge charts is How-Concierge-Analyzes-Spend.md:55-64. It covers hovering over a bar and selecting a bar to open Search. Both still work the same way after this PR.
  • No article under docs/articles mentions blurry charts or chart rendering quality.

mukhrr, a help site PR isn't needed here. If you think an article should cover this change, reply with @MelvinBot and tell me which one.


view run

@izarutskaya

Copy link
Copy Markdown

@mukhrr We will skip step 7 as we don't have access to DEV

In DevTools, with the expanded view open, run [...document.querySelectorAll('canvas')].at(-1) and compare its width with Math.round(getBoundingClientRect().width * devicePixelRatio). Verify the two numbers are equal.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.94-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

6 participants