Skip to content

fix(wasm): Avoid stuck loading screen on startup - #23590

Merged
MartinZikmund merged 1 commit into
masterfrom
dev/mazi/stuckloading
Jul 1, 2026
Merged

MartinZikmund merged 1 commit into
masterfrom
dev/mazi/stuckloading

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #23586

PR Type:

🐞 Bugfix

What changed? 🚀

On the Skia WebAssembly target, apps frequently stayed on the bootstrap loading screen (stuck near 100%) on mobile — almost always on iOS, ~half the time on Android — and on desktop when the tab was backgrounded/minimized during load (requiring an F5). The app was fully running; only the first frame never painted, so the persistent bootstrap loader (kept alive until the app reports its first render) was never removed.

Root cause

The Skia WebAssembly render pump is driven by requestAnimationFrame:
InvalidateRender → requestAnimationFrame → RenderFrame.

BrowserRenderer.RenderFrame() reset _pendingInvalidate = false at the very top, then early-returned when RootElement / CompositionTarget was not ready yet (which happens when a frame fires before app initialization completes — common on slower mobile startups and in throttled background tabs). The queued animation frame was therefore consumed without painting and without rescheduling.

Because CompositionTarget.RenderRequested is only cleared once a render actually happens, it stayed true, so the compositor never issued another InvalidateRender; and the render-request deduplication (_pendingInvalidate) meant nothing re-armed the pump. Splash removal is gated on the FrameRendered event, which never fired — so the loader stayed forever. A touch/drag/scroll/resize revived it only because the TypeScript setCanvasSize() → invalidate() path bypasses the deduplication.

This was a regression: release/stable/6.5 contains neither the readiness guard (d5c6aa12de) nor the deduplication (d2bfc671ad). Before the dedup, every InvalidateRender queued its own frame, so a dropped tick self-healed on the next one.

Fix

In RenderFrame(), move the _pendingInvalidate = false reset below the readiness guard, and in the not-ready branch re-arm another animation frame — but only while a render is genuinely pending (_pendingInvalidate == true), so the deduplication-bypassing TypeScript resize ticks can't cause a busy-loop. The pending request now survives until RootElement is ready, at which point it paints and removes the splash. This self-heals both the mobile first-load race and the desktop background-tab case (a re-armed frame stays queued across rAF throttling and runs on refocus), with no visibilitychange handler needed.

Verified against the other Skia hosts (Win32/X11/Android) — they use continuous frame-pacers and don't have this self-consuming one-shot, so they were never affected and remain unchanged.

PR Checklist ✅

🧪 Testing note: the failure is a startup timing race; it reproduces deterministically by deferring the first few animation frames in DevTools before a hard reload:

const _r = requestAnimationFrame; let n = 0;
window.requestAnimationFrame = cb => n++ < 3 ? setTimeout(() => _r(() => cb(performance.now())), 1500) : _r(cb);

Without the fix the splash stays stuck; with it, the app paints once RootElement is ready. A deterministic automated test requires a small testable seam around the pump decision (extracted method + InternalsVisibleTo); happy to add it as a follow-up if preferred.

🤖 Generated with Claude Code

The Skia WebAssembly render pump is driven by requestAnimationFrame.
RenderFrame() cleared _pendingInvalidate before the readiness guard and
returned without rescheduling when RootElement was not ready yet, so the
single queued frame was lost. Combined with render-request deduplication,
nothing re-armed the pump and the splash screen (gated on FrameRendered)
was never removed, leaving mobile and background-tab loads stuck near 100%.

Re-arm an animation frame in the not-ready branch while a request is still
pending, so it survives until RootElement is ready and the pump self-heals.

Fixes #23586

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_014gUKcEenvQ1Tn9t1zDFUm7
@github-actions github-actions Bot added the platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform label Jun 29, 2026
@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 2m 58s —— View job


Review complete

  • Gather context and read changed file
  • Analyze the diff and review logic
  • Post inline comments for findings
  • Post summary

Summary

Verdict: LGTM with one minor suggestion — 0 blocking issues, 1 minor style nit.

The root cause analysis in the PR description is accurate. The fix is well-targeted:

  1. _pendingInvalidate = false moved after the readiness guard — correct. The original code cleared this flag before checking readiness, so a frame that fired during startup silently consumed the pending request without painting and without self-healing. Moving the reset after the guard preserves the "one pending request outstanding" invariant until an actual render occurs.

  2. Re-arm in the not-ready branch — correct. Calling NativeMethods.Invalidate(_nativeInstance) only when _pendingInvalidate is already true ensures the pump survives the startup race without introducing a busy-loop (the guard prevents re-arming when TypeScript resize ticks trigger a frame with no actual pending request).

  3. No thread-safety concerns — WASM's single-threaded JS event loop means the bool field is safe.

Test coverage — the checklist item is unchecked and the author's rationale (the race needs a testable seam extracted as a follow-up) is reasonable. A note: the JS override snippet in the PR description is a good manual repro; wiring an InternalsVisibleTo path into the pump decision would let a runtime test cover this deterministically without browser DevTools.

One inline suggestion posted — trimming the 4-line comment block to 2 lines and removing the (#23586) issue reference per code-style.md ("A comment states the present reason a line exists; git carries the history").

@unodevops

Copy link
Copy Markdown
Contributor

@MartinZikmund
MartinZikmund merged commit 37016b1 into master Jul 1, 2026
47 checks passed
@MartinZikmund
MartinZikmund deleted the dev/mazi/stuckloading branch July 1, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[WASM Skia] Apps don't start rending app on mobile ("stays" rendering loading page)

3 participants