element-hq / element-hq/element-call
Exclude matrix-rust-sdk-crypto-wasm from embedded packages
- Dominant language
- TypeScript
- Stars
- 996
- Forks
- 213
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 55
Description
### Your use case
#### What would you like to do?
Reduce the size of the platform specific embedded packages (e.g. NPM, AAR, SwiftPM) by excluding the wasm blob from matrix-rust-sdk-crypto-wasm.
#### Why would you like to do it?
Because the wasm blob is never used as in embedded package only supports widget mode which relies on the crypto capabilities of the widget host (e.g. the messenger app).
#### How would you like to achieve it?
Ideally by allowing vite to figure out that it isn't needed for the widget mode and have it excluded automatically.
### Have you considered any alternatives?
_No response_
### Additional context
I tried refactoring to have vite figure out the correct thing. However it turned out that even though the matrix-js-sdk is [lazy loading the rust-crypto](https://github.com/matrix-org/matrix-js-sdk/blob/1def88eb3529aa9b05f8808bc9eb022425de19c8/src/client.ts#L1944) that because [`RoomWidgetClient`](https://github.com/matrix-org/matrix-js-sdk/blob/1def88eb3529aa9b05f8808bc9eb022425de19c8/src/embedded.ts#L146) extends [`MatrixClient`](https://github.com/matrix-org/matrix-js-sdk/blob/1def88eb3529aa9b05f8808bc9eb022425de19c8/src/client.ts#L1169) vite doesn't know that rust-crypto is never loaded.
A possible fix is to refactor the `MatrixClient` by introducing a new abstract class called something like `BaseMatrixClient` that excludes the `initRustCrypto()` function. Then make `MatrixClient` extend `BaseMatrixClient` and add the `initRustCrypto()` back in. In parallel the `RoomWidgetClient` then extends `BaseMatrixClient` and therefore does not include the `initRustCrypto()` function at all.
On the Element Call side some refactor is needed to use these and then, in theory, vite can figure out the right thing to do.
Contributor guide
Assessment
This issue has not been assessed yet.