emscripten-core / emscripten-core/emscripten

Tutorial Request: Creating a canvas component in React/Other

Aperta
#13,151 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub
wontfix
Lingua principale
C++
Stelle
27.6k
Fork
3.6k
Merge medio
1g 14h
PR unite (30g)
125

Descrizione

I've been trying to create my own React component that I can plug into my existing application but failed so far.

Creating a standalone emscripten application works perfectly but I have been facing several errors when trying to inject it dynamically.

Example with React hooks:

const loadWASM = async () => {
const script = document.createElement("script");
script.src = "/public/wasm/browser.js";
script.async = true;

document.body.appendChild(script);
}

This will fail and will result in:

```
browser.js:1 Uncaught TypeError: Cannot read property 'addEventListener' of null
at Object.registerOrRemoveHandler (browser.js:1)
at __registerMouseEventCallback (browser.js:1)
at _emscripten_set_mousemove_callback_on_thread (browser.js:1)
at :3000/public/wasm/browser.wasm:wasm-function[1562]:0xa86bf
at :3000/public/wasm/browser.wasm:wasm-function[1538]:0xa77d9
at :3000/public/wasm/browser.wasm:wasm-function[1606]:0xabd2f
at :3000/public/wasm/browser.wasm:wasm-function[898]:0x6661b
at :3000/public/wasm/browser.wasm:wasm-function[1192]:0x8378a
at Gd (:3000/public/wasm/browser.wasm:wasm-function[1034]:0x70874)
at Module._main (browser.js:1)
```

However, doing this will work perfectly:


var Module = {
canvas: (function() { return document.getElementById('canvas'); })()
};


Creating a guide/tutorial/example-repo on how to build a module that we can inject into any web application, would be something very interesting to have.

Although it is possible to inject it before react loads, after is loads the canvas gets stretched and I've no way of doing state management via redux/react.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by comparing the working canvas/index.js setup with the React hooks example that dynamically loads public/wasm/browser.js, then trace the reported browser.js and browser.wasm errors. A useful result would be a tutorial or example repository showing dynamic canvas integration in React, including state management and avoiding the canvas-stretching problem.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react, wasm
Ambito
documentation, frontend, web-dev
Tipo di issue
Documentazione
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.