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

Remove automatic fetch cache instrumentation #28896

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Apr 23, 2024

This removes the automatic patching of the global fetch function in Server Components environments to dedupe requests using React.cache, a behavior that some RSC framework maintainers have objected to.

We may revisit this decision in the future, but for now it's not worth the controversy.

Frameworks that have already shipped this behavior, like Next.js, can reimplement it in userspace.

I considered keeping the implementation in the codebase and disabling it by setting enableFetchInstrumentation to false everywhere, but since that also disables the tests, it doesn't seem worth it because without test coverage the behavior is likely to drift regardless. We can just revert this PR later if desired.

This removes the automatic patching of the global `fetch` function in
Server Components environments to dedupe requests using `React.cache`,
a behavior that some RSC framework maintainers have objected to.

We may revisit this decision in the future, but for now it's not worth
the controversy.

Frameworks that have already shipped this behavior, like Next.js, can
reimplement it in userspace.

I considered keeping the implementation in the codebase and disabling
it by setting `enableFetchInstrumentation` to `false` everywhere, but
since that also disables the tests, it doesn't seem worth it because
without test coverage the behavior is likely to drift regardless. We
can just revert this PR later if desired.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 23, 2024
@acdlite acdlite requested a review from gnoff April 23, 2024 17:35
@acdlite acdlite marked this pull request as ready for review April 23, 2024 17:35
@react-sizebot
Copy link

Comparing: d4e78c4...5ff57cc

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 497.71 kB 497.71 kB = 88.93 kB 88.93 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 504.00 kB 504.00 kB = 89.95 kB 89.95 kB
facebook-www/ReactDOM-prod.classic.js = 591.14 kB 591.14 kB = 103.91 kB 103.91 kB
facebook-www/ReactDOM-prod.modern.js = 566.95 kB 566.95 kB = 100.12 kB 100.12 kB
oss-experimental/react/cjs/react.react-server.development.js = 79.59 kB 74.64 kB = 22.53 kB 20.93 kB
oss-stable/react/cjs/react.react-server.development.js = 74.03 kB 69.09 kB = 20.95 kB 19.35 kB
oss-stable-semver/react/cjs/react.react-server.development.js = 74.01 kB 69.06 kB = 20.92 kB 19.32 kB
oss-experimental/react/cjs/react.react-server.production.js = 20.89 kB 18.70 kB = 5.55 kB 4.97 kB
oss-stable/react/cjs/react.react-server.production.js = 17.26 kB 15.07 kB = 4.70 kB 4.11 kB
oss-stable-semver/react/cjs/react.react-server.production.js = 17.24 kB 15.04 kB = 4.67 kB 4.08 kB
test_utils/ReactAllWarnings.js Deleted 64.80 kB 0.00 kB Deleted 16.14 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react/cjs/react.react-server.development.js = 79.59 kB 74.64 kB = 22.53 kB 20.93 kB
oss-stable/react/cjs/react.react-server.development.js = 74.03 kB 69.09 kB = 20.95 kB 19.35 kB
oss-stable-semver/react/cjs/react.react-server.development.js = 74.01 kB 69.06 kB = 20.92 kB 19.32 kB
oss-experimental/react/cjs/react.react-server.production.js = 20.89 kB 18.70 kB = 5.55 kB 4.97 kB
oss-stable/react/cjs/react.react-server.production.js = 17.26 kB 15.07 kB = 4.70 kB 4.11 kB
oss-stable-semver/react/cjs/react.react-server.production.js = 17.24 kB 15.04 kB = 4.67 kB 4.08 kB
test_utils/ReactAllWarnings.js Deleted 64.80 kB 0.00 kB Deleted 16.14 kB 0.00 kB

Generated by 🚫 dangerJS against 5ff57cc

@acdlite acdlite merged commit a94838d into facebook:main Apr 23, 2024
38 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 23, 2024
This removes the automatic patching of the global `fetch` function in
Server Components environments to dedupe requests using `React.cache`, a
behavior that some RSC framework maintainers have objected to.

We may revisit this decision in the future, but for now it's not worth
the controversy.

Frameworks that have already shipped this behavior, like Next.js, can
reimplement it in userspace.

I considered keeping the implementation in the codebase and disabling it
by setting `enableFetchInstrumentation` to `false` everywhere, but since
that also disables the tests, it doesn't seem worth it because without
test coverage the behavior is likely to drift regardless. We can just
revert this PR later if desired.

DiffTrain build for [a94838d](a94838d)
@trentonpulse

This comment was marked as abuse.

@Bashamega
Copy link

Bashamega commented May 8, 2024

Hello:)

I think a better idea was to be that there is an option for caching. For example by default there is no caching but if the user passed in the parameter true for caching then to cache.

@1Mouse
Copy link

1Mouse commented May 20, 2024

Hi @acdlite
This modification of removing fetch deduplication by default affects which versions of React?

@kraenhansen
Copy link

One alternative for the future (that has most likely been considered) is for the react package to export its own fetch with this behavior documented.

Con: It would be slightly more verbose and potentially shadow the global when imported.

Pro: App developers can opt into this behavior more explicitly and per file and it won't mess with invariants of the runtime dependent on by libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants