-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Wire up the @apollo/client/cache
entry point
#5577
Conversation
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.
Makes sense to me!
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.
One last suggestion regarding the typeof ReactNS
type.
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.
Preemptively approving, pending the typeof import('react')
changes.
Similar to the changes made in #5541, this commit adds a direct entry point for the Apollo Client cache code. Importing from `@apollo/client/cache` gives access to the cache code directly, without pulling in other parts of the Apollo Client codebase.
When generating the `dist/core/core.cjs.js` entry point (in `config/prepareDist.js`), we filter and re-export the exports we need from the main Apollo Client CJS bundle (to exclude React related code). This means that consumers of `core.cjs.js` attempt to load the full AC CJS bundle first (before filtering exports), which then means the React require in the AC CJS bundle is attempted and not found (since people using `core.cjs.js` want to use Apollo Client without React). To address this, these changes make React an optional require in the CJS bundle.
This commit switches `react` imports around to be `require`d lazliy. This helps us get away from the AST manipulation used in https://github.com/apollographql/apollo-client/pull/5577/commits/8e22edc3e0a61f6c3507b19c289fbfb60ea437f6a, while still allowing React to be required optionally.
573eff8
to
6a5b636
Compare
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.
Similar to the changes made in #5541, this commit adds a direct entry point for the Apollo Client cache code. Importing from
@apollo/client/cache
gives access to the cache code directly, without pulling in other parts of the Apollo Client codebase.