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

Replace requireReactLazily with CJS bundle manipulation #6361

Merged
merged 2 commits into from
May 29, 2020

Conversation

hwillson
Copy link
Member

PR #5577 introduced a new way of lazily loading React to help prevent modern bundlers from requiring React when used with @apollo/client/core (in other words, without any of Apollo Client's React components). While this approach works well for applications that aren't using React, it introduces problems for bundlers and applications that are using React (as outlined in #6035 and #6352). There are several different ways we can address this, and we might do something more substantial in the future, but for now this commit manipulates Apollo Client's core CJS bundle at build time, to make the React require optional.

Fixes #6035.
Fixes #6352.

PR #5577 introduced a new way of lazily loading React
to help prevent modern bundlers from requiring React when used
with `@apollo/client/core` (in other words, without any of
Apollo Client's React components). While this approach works
well for applications that aren't using React, it introduces
problems for bundlers and applications that are using React
(as outlined in #6035 and #6352). There are several different ways
we can address this, and we might do something more substantial
in the future, but for now this commit manipulates Apollo Client's
core CJS bundle at build time, to make the React require optional.

Fixes #6035.
Fixes #6352.
@@ -30,8 +30,8 @@
"dependencies": {
"@apollo/client": "file:../../../../dist",
"graphql": "^14.5.8",
"react": "^16.13.0",
"react-dom": "^16.13.0"
"react": "file:../../../../node_modules/react",
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the bundling example package lock updates, and these dependency changes, aren't directly related to the CJS bundling work in this PR. I did notice they needed to be adjusted while using the bundling app to test this PR's changes, so I thought I would leave them in here.

@hwillson hwillson requested a review from benjamn May 29, 2020 20:05
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

Looks good! I made one tweak to use string splitting to avoid running the regular expression twice.

@hwillson
Copy link
Member Author

Thanks for reviewing/tweaking @benjamn!

@hwillson hwillson merged commit b626268 into master May 29, 2020
@hwillson hwillson deleted the remove-lazy-react-approach branch May 29, 2020 23:05
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@apollo/client v3 broken in Rollup & Snowpack [3.0-beta] Uncaught ReferenceError: require is not defined
2 participants