Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: React Native WebAPIs #2504

Merged
merged 22 commits into from
Jan 12, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- Title: react-native-standard-api
- Title: react-native-webapi
kelset marked this conversation as resolved.
Show resolved Hide resolved
- Date: 2023-07-04
- RFC PR: https://github.com/microsoft/rnx-kit/pull/2504
- rnx-kit Issue: N/A
Expand Down Expand Up @@ -53,8 +53,8 @@ Our goal is not to reimplement a browser, e.g.
a full browser with everything that entails, including modules that they may
never get used. Native apps, and mobile apps especially, cannot be shipped with
unused bits; nor does it make any sense to include MBs of dependencies that are
never used. Ideally, migrating from community modules to the standard API should
not increase the final app size (at least not significantly).
never used. Ideally, migrating from community modules to the WebAPI should not
kelset marked this conversation as resolved.
Show resolved Hide resolved
increase the final app size (at least not significantly).

The API we envision are implemented in the following layers:

Expand Down Expand Up @@ -89,9 +89,9 @@ graph TD;
### Modularity

We want to avoid introducing unused modules and adding unnecessary bloat to the
app bundle. The standard API must therefore be broken down into smaller modules
that can be installed separately. These modules are installed by autolinking,
and must therefore be explicitly added to an app's `package.json`.
app bundle. The WebAPIs must therefore be broken down into smaller modules that
can be installed separately. These modules are installed by autolinking, and
must therefore be explicitly added to an app's `package.json`.
kelset marked this conversation as resolved.
Show resolved Hide resolved

For example, if you want to use `BatteryManager` you should not need to import
the whole `react-native-webapis` module, but only the dedicated
Expand Down Expand Up @@ -164,7 +164,7 @@ dependencies they need to add. At minimum we should:
- A variation of the current proposal without polyfills was considered, but it
would require users to change web code to accommodate native. For instance,
`navigator.getBattery()` would have to be rewritten as
`require("@react-native-api/battery-manager").getBattery()`.
`require("@react-native-webapis/battery-manager").getBattery()`.
- There are many polyfills out there, but they are mostly used to provide
functionalities that are only present in newer ES standards (e.g.
[`Object.assign`][], [`Object.is`][]). We have not found any that address the
Expand Down