Closed thomaseizinger closed 3 years ago
react-scripts
We don't actually directly depend on react-scripts
but react-browser-extension-scripts
.
I've submitted a PR upstream to update that to the latest changes in react-scripts
that come with webpack
5: https://github.com/VasilyShelkov/create-react-extension/pull/32.
It is more or less working (after a lot of playing around). The only problem now is that something is wrong with the URL of the wasm blob which is why it is not yet loaded. But, the much more important finding is that using webpack 5
, we can directly import wasm
modules like any other JS module!
Draft PR here: https://github.com/comit-network/waves/pull/240
Historical context
Currently, importing and using functions from the WASM blob is quite cumbersome.
Our version of CRA depends on webpack 4 which doesn't support asynchronous chunks being loaded as part of the initial request. As a result, we cannot use say:
Where
./wallet
represents the module generated bywasm-bindgen
.Instead we have to use dynamic imports (
await import ("./wallet")
) to access any function defined in the WASM binary.Problems
These dynamic imports impose problems:
Ideas to improve the situation
react-scripts
: https://www.npmjs.com/package/react-scripts/v/5.0.0-next.31This release upgrades to webpack5 which supports loading asynchronous modules as part of the initial chunk. In other words, if we get this working, we can just import the wasm-functions like any other functions from the background script, effectively getting rid of
wasm_proxy.ts
. Note that I think this still doesn't solve the "duplicate wallet" issue if we were to import the wasm from multiple places.Once #227 is merged, message handlers for rpc-messages from the content-script are registered independently. We could therefore experiment with registering a handler through
browser.runtime.onMessage.addListener
directly from within the Rust module. This would cut out on the indirection through the Typescript-based background script.Vision
If we manage to do (1) and (2), we should be able to: