fix(🐛): don't crash when snapshotting a canvas that is not laid out - #4030
Open
woosanggyu wants to merge 3 commits into
Open
fix(🐛): don't crash when snapshotting a canvas that is not laid out#4030woosanggyu wants to merge 3 commits into
woosanggyu wants to merge 3 commits into
Conversation
makeImageSnapshot passed the canvas size (-1 before layoutSubviews) into makeOffscreenSurface, aborting in Metal texture validation, and makeImageSnapshotAsync dereferenced a null view. Return nullptr in both cases so they fall through to the existing snapshot rejection. Adds an example screen (API → Snapshot Before Layout) reproducing Shopify#4029.
woosanggyu
force-pushed
the
fix/make-image-snapshot-size-guard
branch
from
August 25, 2026 11:20
34eb80a to
da86e60
Compare
Author
|
I have signed the CLA! |
wcandillon
self-requested a review
August 30, 2026 15:47
The web smoke test asserts the first canvas on the page is visible; the hidden and zero-size repro canvases were rendered before the visible control canvas.
woosanggyu
force-pushed
the
fix/make-image-snapshot-size-guard
branch
from
August 31, 2026 00:20
9fab0a8 to
2d10f33
Compare
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.
Addresses #4029
Problem
makeImageSnapshotAsync()can abort the process in two ways when theCanvasnative view is not ready:RNSkMetalCanvasProvider::getWidth()/getHeight()return-1while_ctx == nullptr._ctxis only created bysetSize()fromlayoutSubviews, but the view is already registered inwillMoveToSuperview. A snapshot whose main-queue block runs in that window reachesRNSkView::makeImageSnapshotwith size-1, which flows unvalidated intomakeOffscreenSurface:ViewRegistry::getView()returnsnullptr(canvas underdisplay: "none", snapshot right after commit before Fabric mounted the view, or after unmount), the async path dereferences it (view->makeImageSnapshot(...)). The syncmakeImageSnapshotalready null-checks; the async variant did not.Fix
RNSkView::makeImageSnapshot: returnnullptrwhen the canvas size is not positive.RNSkJsiViewApi::makeImageSnapshotAsync: null-check the view before use.Both degrade to the existing
"Failed to make snapshot from view."promise rejection.Repro / verification
Adds
API → 🫥 Snapshot Before Layoutto the example app. It exercises all three cases (hidden canvas, zero-size canvas, remount + snapshot-before-layout loop).main, the remount loop aborts with the Metal assertion above within seconds (iPhone 16 Pro simulator, iOS 26.5); the hidden-canvas button aborts immediately withEXC_BAD_ACCESS.The existing e2e harness drives offscreen surfaces over a socket and does not exercise the RN view lifecycle, so this is kept as an example screen rather than an automated e2e test.
We have been running the size guard as a local patch in production since 2.10.1 and the crash signature disappeared.
Before the fix (
main) — aborts within secondsskia-4029-before-fix.mp4
After the fix — 30 s of the remount loop, rejections instead of a crash
skia-4029-after-fix.mp4