Skip to content

Commit

Permalink
Revert fetch instrumentation to only RSC (#25540)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage authored Oct 23, 2022
1 parent 0c11baa commit caa84c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/react/src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/ReactSharedSubset.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* @flow
*/

// Patch fetch
import './ReactFetch';

export {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
Children,
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/__tests__/ReactFetch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit caa84c8

Please sign in to comment.