Open2

react-strict-domについてのメモ

ピン留めされたアイテム
kazutoyokazutoyo

React Strict DOM (0.0.1)が公開された。それについてのメモ。
https://github.com/facebook/react-strict-dom

React Strict DOMのモチベーション

necolas氏のこちらのRFCより。
https://github.com/react-native-community/discussions-and-proposals/pull/496

React NativeはiOSやAndroidのネイティブアプリのAPIを抽象化したAPIを提供し、そのAPIを使ってモバイルのアプリケーションを構築する。
また、React Native for WebでReact NativeアプリケーションをWebのAPIに変換をすることでWebプラットフォーム上でも動作することができるが、その変換層でオーバーヘッドがあるためパフォーマンスなどの欠点がある。(次の図のようにreact-native-webでは約70kBほど増えてしまうそう)
React Native API
RFC: React DOM for Native (reduce API fragmentation)

React Strict DOMでは、Web標準のAPIに準拠した「Strict DOM」サブセットをReact Native上に実装し、Webでのオーバーヘッドを少なくすることを目的にします。

React Strict DOM API
RFC: React DOM for Native (reduce API fragmentation)

またReact Nativeでのイベントループ処理モデルがWeb仕様に合わせるようになっている。(New React Native architectureのみ)
https://github.com/rubennorte/discussions-and-proposals/blob/proposal-event-loop/proposals/0744-well-defined-event-loop.md

kazutoyokazutoyo

とりあえず動かす

0.0.1時点のreact-strict-domのリポジトリのExample Appを動かしてみた。
https://github.com/facebook/react-strict-dom/tree/main/apps/examples

https://x.com/kazutoyo/status/1760236517879058501?s=20

現在のWeb APIに対応するiOS/Androidの互換性は COMPATIBILITY.md で確認できる。

0.0.1なのでまだまだこれから対応するものが多いが、これらのAPIをすべて対応させるのもかなり大変そうな作業だ…

色々試した方

with NativeWind

NativeWindでスタイリングができている
https://twitter.com/Baconbrix/status/1760327319892234280

with React Native Reanimated

https://x.com/tomekzaw_/status/1761073014202839051?s=20