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

feat: add react-native polyfills #1915

Merged
merged 13 commits into from
Apr 2, 2024
Merged

feat: add react-native polyfills #1915

merged 13 commits into from
Apr 2, 2024

Conversation

weboko
Copy link
Collaborator

@weboko weboko commented Mar 13, 2024

Problem

ReactNative can use two types of bundler:

Following dependencies were a cause of failure for ReactNative app:

dns-query
- require("url")

multiformats
- TextEncoder
- TextDecoder

@libp2p/interfaces
- EventTarget

Solution

Metro bundler is still not compatible by default with exports map so unstable_enablePackageExports should be enabled explicitly.

As for problems with polyfills - this package addresses it.

@weboko weboko force-pushed the weboko/react-native branch from b5e8b17 to 359b197 Compare March 26, 2024 11:43
@weboko weboko changed the title feat: add react-native exports feat: add react-native polyfills Mar 26, 2024
Copy link

github-actions bot commented Mar 26, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku node 185.75 KB (0%) 3.8 s (0%) 3.9 s (+43.4% 🔺) 7.6 s
Waku Simple Light Node 185.45 KB (0%) 3.8 s (0%) 2.5 s (-30.58% 🔽) 6.2 s
ECIES encryption 22.88 KB (0%) 458 ms (0%) 1.1 s (+11.86% 🔺) 1.6 s
Symmetric encryption 22.42 KB (0%) 449 ms (0%) 824 ms (+15.83% 🔺) 1.3 s
DNS discovery 73.67 KB (0%) 1.5 s (0%) 3.2 s (+27.14% 🔺) 4.6 s
Peer Exchange discovery 75.37 KB (0%) 1.6 s (0%) 2.6 s (+19.21% 🔺) 4.1 s
Local Peer Cache Discovery 68.99 KB (0%) 1.4 s (0%) 2.8 s (-2.91% 🔽) 4.2 s
Privacy preserving protocols 39.97 KB (0%) 800 ms (0%) 2.6 s (+46.91% 🔺) 3.4 s
Waku Filter 20.11 KB (0%) 403 ms (0%) 760 ms (-24.96% 🔽) 1.2 s
Waku LightPush 115.41 KB (0%) 2.4 s (0%) 3.8 s (+17.56% 🔺) 6.1 s
History retrieval protocols 116.05 KB (0%) 2.4 s (0%) 4.6 s (+13.72% 🔺) 6.9 s
Deterministic Message Hashing 4.96 KB (0%) 100 ms (0%) 103 ms (+17.35% 🔺) 202 ms

@@ -5,7 +5,7 @@ jobs:
pre-release:
name: pre-release
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master'
if: github.event_name == 'workflow_dispatch'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side change to allow publishing from other branches

@@ -0,0 +1,77 @@
{
"name": "@waku/polyfills",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waku-org/js-waku-developers how do you like the name? It is intended for ReactNative polyfilling.
I'd like to avoid long two worded names if possible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, considering it's just for react-native, i would personally prefer to have that part of the package name for max verbosity

maybe in the future when we have different kinds of polyfills, this name would make more sense :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to react-native-polyfills

@weboko weboko marked this pull request as ready for review March 27, 2024 12:30
@weboko weboko requested a review from a team as a code owner March 27, 2024 12:30
@@ -0,0 +1 @@
# Changelog
Copy link
Collaborator

@danisharora099 danisharora099 Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need this file? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@danisharora099 danisharora099 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i might not understand this, but: where are the poylfills? :P

Comment on lines 6 to 7
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require("path");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason we aren't doing es6 imports?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no in particular, es6 is longer so I usually prefer require style
changed here to see if it would work with metro

],
"scripts": {
"build": "run-s build:**",
"build:esm": "tsc",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important to note that rollup will not be bundling this package as bundling not needed and should be figured out by react-native application

@weboko weboko requested a review from danisharora099 March 28, 2024 23:58
@weboko weboko merged commit 9be942f into master Apr 2, 2024
8 of 10 checks passed
@weboko weboko deleted the weboko/react-native branch April 2, 2024 11:53
@weboko weboko mentioned this pull request Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants