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

Wire up the @apollo/client/cache entry point #5577

Merged
merged 4 commits into from
Nov 15, 2019
Merged

Conversation

hwillson
Copy link
Member

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.

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.

Makes sense to me!

config/rollup.config.js Outdated Show resolved Hide resolved
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.

One last suggestion regarding the typeof ReactNS type.

src/react/react.ts Outdated Show resolved Hide resolved
src/react/react.ts Outdated Show resolved Hide resolved
src/react/react.ts Outdated Show resolved Hide resolved
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.

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.
@hwillson hwillson merged commit 2098d1b into release-3.0 Nov 15, 2019
@hwillson hwillson deleted the cache-entry-point branch November 15, 2019 18:53
hwillson added a commit that referenced this pull request May 29, 2020
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.
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants