Repository navigation
fix(🐛): install the native module before the flag constants are read - #530
Merged
Merged
Conversation
The flags the package exports (GPUBufferUsage, GPUTextureUsage, GPUShaderStage, GPUColorWrite, GPUMapMode from src/constants.ts) were all undefined. constants.ts reads them from globalThis while it is evaluated, and main/index.tsx reached it through its own imports (../install imports ./constants) before its body called WebGPUModule.install(): every import of a module is evaluated before its body. Code following the README pattern, importing the flags into a worklet, captured undefined: `Cannot read property 'RENDER_ATTACHMENT' of undefined` on the first texture created from a worklet, which aborts a release build when it happens in a frame callback. The install moves to main/installNative.ts, the first import of main/index.tsx, and a bare one so that inlineRequires cannot defer it. Checked in a production Metro bundle (expo export, iOS): the install module is now required first, before ../install and ../constants. The example app passes the exported flags to the E2E context, and Constants.spec.ts checks they are the installed globals (native app only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K65ZmjbaHYsZuwbq9E8S9X
wcandillon
self-requested a review
October 15, 2026 05:45
…st mock the flag constants - `src/index.tsx` starts with a bare `import "./main/installNative"` (the shape of react-native-skia's `import "./skia/NativeSetup"`), so the order of the `export *` lines no longer decides whether `constants.ts` sees the globals. `installNative.web.ts` carries the RNWebGPU polyfill so web never reaches the TurboModule. - `installNative.ts` throws when `RNWebGPU` is missing after `install()` instead of warning: nothing works past that point. - `install.ts` reads `RNWebGPU.gpu` at module scope; the holder and `provideGPUForInstall` only existed to survive the old evaluation order. - `mock.ts` defines the spec bit values of the five flag objects and puts them on globalThis; it used to re-export `./constants`, which nothing installs under Jest.
wcandillon
approved these changes
Oct 15, 2026
Owner
|
Thanks a lot! |
|
🎉 This PR is included in version 0.15.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
The bug
The flags the package exports from
src/constants.ts(GPUBufferUsage,GPUTextureUsage,GPUShaderStage,GPUColorWrite,GPUMapMode) are allundefinedat runtime.constants.tsreads them fromglobalThiswhile it is evaluated.main/index.tsxreaches it through its own imports (../installimports./constants) before its body callsWebGPUModule.install(), because every import of a module is evaluated before that module's body. So the globals don't exist yet whenconstants.tsreads them, and the comment there (which says./maininstalls first) doesn't hold.Code that follows the documented pattern, importing a flag into a worklet, captures
undefined. For example,@azzapp/react-native-skia-video1.0 creates its frame textures in a worklet and getsCannot read property 'RENDER_ATTACHMENT' of undefined. In a release build, that exception thrown from a frame callback aborts the app. We saw it on an iPhone as soon as a video was shown.The fix
WebGPUModule.install()moves tomain/installNative.ts, whichmain/index.tsximports first.import "./installNative". An import with bindings can be deferred to its first use byinlineRequires; a bare one stays in place.constants.tsnow describes the actual order.Verification
expo export --platform ios, production) against these sources. The install module is now required first inmain/index.tsx, before../installand../constants. Before the change,../install→./constantswas evaluated first.