Revert fetch instrumentation to only RSC (#25540)

Revert fetch instrumentation so that it only affects RSC by applying it
only in the react-server condition of "react".

This helps make the rollout a little smoother because these affects
existing libraries that fetch during client components, and then gets
forever cached. We need to implement the GC first.

I haven't fully implemented the SSR part anyway.

The main problem that we discovered is that `"react"` and
`"react/react.shared-subset"` have separate dispatchers in an
environment that runs both Fizz and Flight. That's intentional and
sometimes a feature. However, in this case it means that we instrument
fetch twice and when you run Flight inside Fizz, that fetch goes into
both caches when it's supposed to only see the inner one. I'm not sure
how to solve that atm.
This commit is contained in:
Sebastian Markbåge
2022-10-22 22:58:30 -04:00
committed by GitHub
parent 0c11baa6ab
commit caa84c8da0
3 changed files with 6 additions and 3 deletions

View File

@@ -71,9 +71,6 @@ import ReactSharedInternals from './ReactSharedInternals';
import {startTransition} from './ReactStartTransition';
import {act} from './ReactAct';
// Patch fetch
import './ReactFetch';
// TODO: Move this branching into the other module instead and just re-export.
const createElement: any = __DEV__
? createElementWithValidation

View File

@@ -7,6 +7,9 @@
* @flow
*/
// Patch fetch
import './ReactFetch';
export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
Children,

View File

@@ -41,6 +41,9 @@ describe('ReactFetch', () => {
fetchCount = 0;
global.fetch = fetchMock;
if (gate(flags => flags.experimental && !flags.www)) {
jest.mock('react', () => require('react/react.shared-subset'));
}
React = require('react');
ReactServerDOMServer = require('react-server-dom-webpack/server.browser');
ReactServerDOMClient = require('react-server-dom-webpack/client');