Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a WebAssembly Skia host sizing issue where some mobile browsers can fire window.resize before document.documentElement has reflowed after rotation, leaving the Skia surface (and input mapping) stuck with stale dimensions. It adds a ResizeObserver-based corrective path in the WASM host and includes a manual SamplesApp telemetry page to validate behavior on real devices/browsers.
Changes:
- Add a
ResizeObserverondocument.documentElementto re-dispatch a syntheticwindow.resizeonce the viewport has settled after rotation. - Harden the managed JS-exported resize callback to prevent exceptions from escaping into the JS DOM-event callback.
- Add a manual telemetry sample to compare
XamlRoot.Sizevs DOM viewport size and show “STALE/OK”.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Uno.UI.Runtime.Skia.WebAssembly.Browser/UI/Xaml/Window/WebAssemblyWindowWrapper.cs | Wraps JS-exported resize callback with try/catch and routes managed exceptions to recoverable handling. |
| src/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/WebAssemblyWindowWrapper.ts | Adds ResizeObserver on documentElement to re-dispatch resize after post-rotation layout settles. |
| src/SamplesApp/SamplesApp.Samples/Wasm/Wasm_ViewportOrientationTelemetry.xaml.cs | Adds manual telemetry page that polls DOM viewport rect + event counters and compares to XamlRoot.Size. |
| src/SamplesApp/SamplesApp.Samples/Wasm/Wasm_ViewportOrientationTelemetry.xaml | UI for the telemetry page (status banner + reported sizes/event counters). |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24216/wasm-skia-net9/index.html |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24216/wasm-skia-net9/index.html |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/UI/Xaml/Window/WebAssemblyWindowWrapper.cs:107
- In this JSExport callback, the null-safe exception helper logs using
sender.GetType()whenApplication.Currentis null. Passingtypeof(WebAssemblyWindowWrapper)means the log category becomesSystem.RuntimeType, which makes startup exceptions harder to triage. Capture the actualWebAssemblyWindowWrapperinstance (when available) and pass it toRaiseRecoverableUnhandledExceptionOrLog; fall back totypeof(WebAssemblyWindowWrapper)only when no instance was created.
This issue also appears on line 133 of the same file.
{
// A managed exception must not cross back into the JS DOM-event callback.
// Null-safe: the initial resize runs before Application.Start.
Application.Current.RaiseRecoverableUnhandledExceptionOrLog(e, typeof(WebAssemblyWindowWrapper));
}
src/Uno.UI.Runtime.Skia.WebAssembly.Browser/UI/Xaml/Window/WebAssemblyWindowWrapper.cs:137
- Same as OnResize: when
Application.Currentis null, passingtypeof(WebAssemblyWindowWrapper)toRaiseRecoverableUnhandledExceptionOrLoglogs underSystem.RuntimeType. Preserve the real wrapper instance (when available) so early-startup exceptions are logged under the correct type.
{
// A managed exception must not cross back into the JS DOM-event callback.
// Null-safe: visualViewport events can fire before Application.Start.
Application.Current.RaiseRecoverableUnhandledExceptionOrLog(e, typeof(WebAssemblyWindowWrapper));
}
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24216/wasm-skia-net9/index.html |
|
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24216/wasm-skia-net9/index.html |
|
|
|
Tick the box to add this pull request to the merge queue (same as
|
|
@Mergifyio backport release/stable/6.7 |
✅ Backports have been createdDetails
|
…6.7/pr-24216 fix(wasm): Redispatch resize once viewport settles after rotation (backport #24216)
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/orientationchangebefore the layout viewport (document.documentElement) has actually reflowed to the new size, and never fire a correctiveresizeafterward. SinceWebAssemblyWindowWrappersizes the window (and thus the Skia surface) fromdocumentElement.getBoundingClientRect()inside that earlyresizehandler, 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
ResizeObserverondocument.documentElement— the exact elementresize()measures from — in the Skia WASM host.ResizeObserverfires 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 syntheticwindow.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 everyresize(), 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 withoutResizeObserverkeep the previous behavior.The fix is host-level and benefits app code too: application-level
window.resizelisteners were equally stale, and now receive the corrective event. Dispatching the global event (rather than re-measuring internally) is deliberate —BrowserRenderersizes the canvas from its ownwindow.resizelistener, so an internal-only re-measure would fix the window bounds but leave the canvas stale.Design notes / scope:
window.resizelistener 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 firesresizewithout changingdocumentElement's CSS size, which aResizeObservercannot see).uno.csspinshtml/bodyand the canvas toposition: fixed; width/height: 100%; overflow: hidden, so the viewport drivesdocumentElement— never the canvas — andresize()records the last measured size, making the observer a no-op whenever a native resize already handled the change.WindowManager.tsand may exhibit the same staleness, but per the Skia-first policy it is maintenance-only and intentionally out of scope here.RasterizationScaleon zoom/monitor moves) is a pre-existing, unrelated behavior and is unchanged.PR Checklist ✅
Wasm_ViewportOrientationTelemetry(Wasm category), which live-comparesXamlRoot.SizeagainstdocumentElement.getBoundingClientRect()with a STALE/OK banner and rawresize/orientationchangecounters, so the symptom and the fix are directly observable on a device.SamplesApp.Skia.WebAssembly.Browserserved 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.Screenshots Compare Test Runresults.Credit: the root-cause analysis and the proposed
ResizeObserverapproach come from the reporting customer's investigation.