fix: transform image demo crash by pinning @emnapi to 1.8.1#450
Open
DaanyaalSobani wants to merge 1 commit intonapi-rs:mainfrom
Open
fix: transform image demo crash by pinning @emnapi to 1.8.1#450DaanyaalSobani wants to merge 1 commit intonapi-rs:mainfrom
DaanyaalSobani wants to merge 1 commit intonapi-rs:mainfrom
Conversation
The image transform demo on the homepage threw 'Cannot read properties of undefined (reading whenLoaded)' in Chrome because @emnapi/core 1.10.0 (resolved by @napi-rs/wasm-runtime) uses the new pthread_create-based worker model, while the prebuilt @napi-rs/image-wasm32-wasi .wasm is still linked against the older worker-pool model from emnapi 1.8.x. Pinning the JS runtime to 1.8.1 realigns the two halves. Also adds COOP/COEP/CORP response headers via next.config.js so that /_next/static/* assets satisfy cross-origin isolation (middleware.js can't reach those paths), which is a separate prerequisite for SharedArrayBuffer-backed wasm threading. Refs napi-rs/napi-rs#3262
|
@DaanyaalSobani is attempting to deploy a commit to the napi-rs Team on Vercel. A member of the Team first needs to authorize it. |
Author
Recording.2026-04-30.185711.mp4Video showing the button is working after applying the fix. |
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.
Summary
Fixes the homepage's "Transform Image App" demo, which throws
TypeError: Cannot read properties of undefined (reading 'whenLoaded')in Chrome on click.Refs napi-rs/napi-rs#3262
Root cause
@napi-rs/image-wasm32-wasi's prebuilt.wasmis linked against emnapi 1.8.x, which uses an internal worker-pool to track threads. But@napi-rs/wasm-runtimeresolves@emnapi/coreto^1.7.1, which in practice installs 1.10.0 — and from 1.9.0 onward, emnapi switched to delegating topthread_createand stopped maintaining a separate pool. The JS runtime then reads atidfrom a memory location the prebuilt wasm never populates, soPThread.pthreads[tid]isundefinedwheninitWorkerstries to read.whenLoadedon it.This is the same mismatch reported and explained in toyobayashi/emnapi#202.
Changes
package.json: pin@emnapi/coreand@emnapi/runtimeto1.8.1viaresolutionsso the JS runtime matches what the prebuilt.wasmwas linked against.next.config.js: add COOP/COEP at the document level andCross-Origin-Resource-Policy: same-originon/_next/static/*.middleware.jsalready set COOP/COEP on HTML, but Next.js middleware doesn't run on/_next/static/*, so static worker chunks lacked CORP — required underCross-Origin-Embedder-Policy: require-corpforSharedArrayBuffer-backed wasm threading.Test plan
yarn dev→ open homepage → click Transform image to webp → completes successfully (previously threw)crossOriginIsolated === trueimage.wasm32-wasi.*.wasmrequests return 200