-
Notifications
You must be signed in to change notification settings - Fork 30
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
[polyfills] Bundling of package dependencies #237
Conversation
# Conflicts: # packages/react-native/package.json # pnpm-lock.yaml
# Conflicts: # packages/react-native/package.json # pnpm-lock.yaml
# Conflicts: # packages/common/package.json # packages/react-native/package.json # packages/web/package.json # pnpm-lock.yaml
# Conflicts: # packages/react-native/package.json # pnpm-lock.yaml
🦋 Changeset detectedLatest commit: 5642b97 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
'@powersync/web > lodash/throttle', | ||
'@powersync/web > can-ndjson-stream' | ||
] | ||
include: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By having an empty array instead of omitting the field, it silences a vite warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with this from my side
# Conflicts: # packages/react-native/package.json # pnpm-lock.yaml
Introduction
This PR aims to reduce the amount of setup required to use the PowerSync-js SDKs. This setup typically includes dependencies/polyfills and sometimes minor code additions in a project to ensure that the polyfills are applied.
Original React Native Polyfills can be found here.
Original Web Polyfills can be found here. Web only needed buffer.
Rollup
By using Rollup for bundling we could include and process the polyfills so that consumers of the
common
,web
, andreact-native
packages no longer need the majority of the listed polyfills.This was done using a combination rollup plugins:
This bundling was only applied to
common
andreact-native
, as there was a few blockers found withweb's
workers and no additional setup gains needed beyond whatweb
inherits by being a consumer ofcommon
.Vendoring Crypto
For
react native
BSON has a crypto warning which I silenced by vendoring/modifying thereact-native-get-random-values
package so that it doesn't act as a polyfill but rather a ponyfill. The ponyfill is then injected global crypto references.Checklist
Testing
To verify that this diff works I ran manual tests against the majority of the demos + diag tool inside the monorepo as well as against standalone copies. Before the tests I removed all polyfill related code/dependencies that are no longer needed.
For the
react-native-supabase-todolist
andreact-supabase-todolist
demos I tested both HTTP and Web socket connectionmethods.Bundle sizes
Since dependencies are being bundled in our packages now it's worth looking at the changes in the packages:
Original:
Common: 250 KB
Web: 428 KB
React Native: 30 KB
After:
Common: 4.5 MB (1.4Mb for JS, 3.2MB for type map)
Web: 345KB
React Native: 5.8 MB (1.7Mb for js, 4.2Mb for type map)
With Terser:
Common: 3.1 MB (830Kb for js, 2.3 MB for typings)
Web: 330KB
React Native: 4.2 MB (1.3 MB for js, 3 MB for typings)
Effective change if using terser (minified) (no sourcemap in release):
Common: 250 KB -> 830KB
Web: 428 KB -> 214 KB
React Native: 30KB-> 1.3 MB
It looks like a lot of the bloat is coming from having bundled text-encoding twice (once from BSON that is prebundling it, and once from our side).
However, after comparing different react-native demo builds - it doesn't appear to make a substantial difference in a final app build (100KB Variance).
Future work
@azure/core-asynciterator-polyfill
. I didn't do this as it's supported an optional way of using the SDKs, and might have a few unknowns alongside the babel setup.