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:
Currently
frenderandreact-rsrely onreact-systo work.react-sysuses a feature flagimport-reactto control whether to import fromreactmodule or just use global variableReact.A better design could be as following:
frenderandreact-rsshouldn't rely on any runtime implementation details (e.g. where React is imported).Instead, they provide a trait
ReactRuntimedefining common behaviors.For libraries, they also rely on the
ReactRuntimetrait to call hooks and create elements.For binaries, only at
frender::mainor 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-bindgenand can run in server side. (SSR might be implemented with this)frenderis 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:react-rsandfrender, wasm-bindgen and other wasm-related dependencies should be under optional featurejs.impl AsRef<JsValue>must be removed as they no longer contain JsValue.Into<JsValue>can only be implemented with featurejs.react-rs, provideRuntimetrait, which defines common behaviors of React runtime.react-rsshould maintain a thread_local static cell of runtime instance and this can be set once (maybeOnceCell<Box<dyn Runtime>>)frendershould re-pubreact::RuntimeasReactRuntime