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

Add a "compat" entry point that works with React 16.9+ and 17 #1842

Merged
merged 7 commits into from
Nov 19, 2021

Conversation

markerikson
Copy link
Contributor

@markerikson markerikson commented Nov 19, 2021

This PR:

  • Adds a new "compat" entry point that falls back to the useSyncExternalStore shim, enabling compatibility with React 16.9+ and 17 if used instead of the default entry point
  • Updates the testing config to run all tests while overriding the React package versions to point to React 17 instead of 18 and overriding the test files to import from the "compat" entry point instead, to verify that the same implementation works against both React versions
  • Removes the loose-envify dependency and the browserify key from package.json. If you're still using Browserify and this is somehow needed, please configure your own build setup to transpile this package accordingly.

We use the same trick we do with batchedUpdates: a module with
variables + getter/setter functions. Each entry point is then
responsible for importing the right variables and setting them.
This happens before the modules are loaded, so we can then import
the getters where they're needed and call them to get the right
instances of `useSyncExternalStore`.

The "compat" and "alternate-renderer" entry points both use the
`uSES` shim, so they should be compatible back to React 16.9+.
The primary entry point imports directly from React, and thus
assumes React 18.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 19, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 87d1ec4:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration

@netlify
Copy link

netlify bot commented Nov 19, 2021

✔️ Deploy Preview for react-redux-docs ready!

🔨 Explore the source changes: 87d1ec4

🔍 Inspect the deploy log: https://app.netlify.com/sites/react-redux-docs/deploys/619725af6087f1000887c035

😎 Browse the preview: https://deploy-preview-1842--react-redux-docs.netlify.app

@github-actions
Copy link

github-actions bot commented Nov 19, 2021

Size Change: +1.57 kB (7%) 🔍

Total Size: 21.2 kB

Filename Size Change
dist/react-redux.js 16.1 kB +1.02 kB (6%) 🔍
dist/react-redux.min.js 5.08 kB +553 B (10%) ⚠️

compressed-size-action

@markerikson markerikson merged commit 19ae75e into master Nov 19, 2021
@markerikson markerikson deleted the feature/uses-compat-shim branch November 19, 2021 04:23
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.

1 participant