Skip to content

fix(wasm): Redispatch resize once viewport settles after rotation (backport #24216) - #24265

Merged
kazo0 merged 12 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-24216
Aug 29, 2026
Merged

kazo0 merged 12 commits into
release/stable/6.7from
mergify/bp/release/stable/6.7/pr-24216

Conversation

@mergify

@mergify mergify Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: n/a — customer-reported, tracked internally.

PR Type:

🐞 Bugfix

What changed? 🚀

Current behavior: in a WebAssembly app using the Skia renderer, rotating the device between portrait and landscape can leave the app rendered at the wrong dimensions (controls squished / at the wrong scale). Some mobile browsers — observed with Chrome on iPad, while Safari is fine — fire resize / orientationchange before the layout viewport (document.documentElement) has actually reflowed to the new size, and never fire a corrective resize afterward. Since WebAssemblyWindowWrapper sizes the window (and thus the Skia surface) from documentElement.getBoundingClientRect() inside that early resize handler, it keeps the stale pre-rotation dimensions until some other event forces a re-measure. Because rendering and input mapping both use the stale size, taps also land offset from the visuals.

This PR installs a ResizeObserver on document.documentElement — the exact element resize() measures from — in the Skia WASM host. ResizeObserver fires after layout, i.e. precisely when the element has actually settled to its post-rotation size. When the observed size differs from the last size the host measured, it re-dispatches a synthetic window.resize, restoring the corrective event the browser should have fired; the existing resize path then re-measures against the settled dimensions. The host records the last measured size on every resize(), so when a native resize already handled the change the observer callback no-ops — no redundant dispatches, no loops (the observer only fires on actual size changes). Browsers without ResizeObserver keep the previous behavior.

The fix is host-level and benefits app code too: application-level window.resize listeners were equally stale, and now receive the corrective event. Dispatching the global event (rather than re-measuring internally) is deliberate — BrowserRenderer sizes the canvas from its own window.resize listener, so an internal-only re-measure would fix the window bounds but leave the canvas stale.

Design notes / scope:

  • The window.resize listener stays the primary size source; the observer is only the corrective for the mis-ordered case. The native listener uniquely covers DPR-only resizes (browser zoom fires resize without changing documentElement's CSS size, which a ResizeObserver cannot see).
  • No feedback-loop risk: uno.css pins html/body and the canvas to position: fixed; width/height: 100%; overflow: hidden, so the viewport drives documentElement — never the canvas — and resize() records the last measured size, making the observer a no-op whenever a native resize already handled the change.
  • The native (non-Skia) WebAssembly target has the same measure-on-resize pattern in WindowManager.ts and may exhibit the same staleness, but per the Skia-first policy it is maintenance-only and intentionally out of scope here.
  • DPR-only staleness (RasterizationScale on zoom/monitor moves) is a pre-existing, unrelated behavior and is unchanged.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable)
    • The race requires physically rotating a device and a browser that mis-orders the events, so it is not runtime-testable. Added the manual sample Wasm_ViewportOrientationTelemetry (Wasm category), which live-compares XamlRoot.Size against documentElement.getBoundingClientRect() with a STALE/OK banner and raw resize/orientationchange counters, so the symptom and the fix are directly observable on a device.
    • Manual validation on a physical iPad in Chrome (the affected combination): without the fix the stale size reproduces after rotation and sticks; with the fix (validated both as the patched host in the published SamplesApp.Skia.WebAssembly.Browser served over LAN, and as the equivalent logic A/B-toggled in a telemetry repro app) every rotation converges to the settled viewport size. Safari behavior is unchanged.
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features)
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes

Credit: the root-cause analysis and the proposed ResizeObserver approach come from the reporting customer's investigation.


This is an automatic backport of pull request #24216 done by [Mergify](https://mergify.com).

@github-actions github-actions Bot added platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform area/automation Categorizes an issue or PR as relevant to project automation labels Aug 28, 2026
@kazo0

kazo0 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

@ajpinedam

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@unodevops

Copy link
Copy Markdown
Contributor

@kazo0
kazo0 merged commit c580655 into release/stable/6.7 Aug 29, 2026
47 checks passed
@kazo0
kazo0 deleted the mergify/bp/release/stable/6.7/pr-24216 branch August 29, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants