frender icon indicating copy to clipboard operation
frender copied to clipboard

Make frender runtime-independent

Open EqualMa opened this issue 3 years ago • 0 comments

Currently frender and react-rs rely on react-sys to work. react-sys uses a feature flag import-react to control whether to import from react module or just use global variable React.

A better design could be as following:

frender and react-rs shouldn't rely on any runtime implementation details (e.g. where React is imported). Instead, they provide a trait ReactRuntime defining common behaviors. For libraries, they also rely on the ReactRuntime trait to call hooks and create elements. For binaries, only at frender::main or the beginning of main fn should the runtime be specified globally.

Going further, there could be a pure rust implementation of the runtime, which is independent of wasm-bindgen and can run in server side. (SSR might be implemented with this)

frender is at v1-alpha versions. BREAKING CHANGES are unavoidable to apply the new design. But I will make as least BREAKING CHANGES as possible with the following todos:

  • [ ] In react-rs and frender, wasm-bindgen and other wasm-related dependencies should be under optional feature js.
    • [x] Some impl AsRef<JsValue> must be removed as they no longer contain JsValue.
    • [ ] Into<JsValue> can only be implemented with feature js.
  • [ ] In react-rs, provide Runtime trait, which defines common behaviors of React runtime.
    • [ ] react-rs should maintain a thread_local static cell of runtime instance and this can be set once (maybe OnceCell<Box<dyn Runtime>>)
    • [ ] frender should re-pub react::Runtime as ReactRuntime

EqualMa avatar Apr 29 '22 15:04 EqualMa