Skip to content

Commit e359b14

Browse files
timneutkenshuozhi
andauthored
Upgrade react@beta (#65845)
Ensures `useMemoCache` is available for the React Compiler. Required for #65804 without having to manually enable experimental React through e.g. taint: true. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> --------- Co-authored-by: Jiachi Liu <[email protected]>
1 parent 9f647f3 commit e359b14

File tree

117 files changed

+2450
-1685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+2450
-1685
lines changed

examples/reproduction-template-pages/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
},
88
"dependencies": {
99
"next": "canary",
10-
"react": "19.0.0-beta-4508873393-20240430",
11-
"react-dom": "19.0.0-beta-4508873393-20240430"
10+
"react": "19.0.0-beta-04b058868c-20240508",
11+
"react-dom": "19.0.0-beta-04b058868c-20240508"
1212
},
1313
"devDependencies": {
1414
"@types/node": "20.4.5",

examples/reproduction-template/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
},
88
"dependencies": {
99
"next": "canary",
10-
"react": "19.0.0-beta-4508873393-20240430",
11-
"react-dom": "19.0.0-beta-4508873393-20240430"
10+
"react": "19.0.0-beta-04b058868c-20240508",
11+
"react-dom": "19.0.0-beta-04b058868c-20240508"
1212
},
1313
"devDependencies": {
1414
"@types/node": "20.4.5",

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"alex": "9.1.0",
121121
"amphtml-validator": "1.0.35",
122122
"async-sema": "3.0.1",
123+
"babel-plugin-react-compiler": "0.0.0-experimental-c23de8d-20240515",
123124
"browserslist": "4.22.2",
124125
"buffer": "5.6.0",
125126
"cheerio": "0.22.0",
@@ -196,17 +197,17 @@
196197
"pretty-bytes": "5.3.0",
197198
"pretty-ms": "7.0.0",
198199
"random-seed": "0.3.0",
199-
"react": "19.0.0-beta-4508873393-20240430",
200+
"react": "19.0.0-beta-04b058868c-20240508",
200201
"react-17": "npm:[email protected]",
201-
"react-builtin": "npm:[email protected]4508873393-20240430",
202-
"react-dom": "19.0.0-beta-4508873393-20240430",
202+
"react-builtin": "npm:[email protected]04b058868c-20240508",
203+
"react-dom": "19.0.0-beta-04b058868c-20240508",
203204
"react-dom-17": "npm:[email protected]",
204-
"react-dom-builtin": "npm:[email protected]4508873393-20240430",
205+
"react-dom-builtin": "npm:[email protected]04b058868c-20240508",
205206
"react-dom-experimental-builtin": "npm:[email protected]",
206207
"react-experimental-builtin": "npm:[email protected]",
207-
"react-server-dom-turbopack": "19.0.0-beta-4508873393-20240430",
208+
"react-server-dom-turbopack": "19.0.0-beta-04b058868c-20240508",
208209
"react-server-dom-turbopack-experimental": "npm:react-server-dom-turbopack@0.0.0-experimental-4508873393-20240430",
209-
"react-server-dom-webpack": "19.0.0-beta-4508873393-20240430",
210+
"react-server-dom-webpack": "19.0.0-beta-04b058868c-20240508",
210211
"react-server-dom-webpack-experimental": "npm:[email protected]",
211212
"react-ssr-prepass": "1.0.8",
212213
"react-virtualized": "9.22.3",
@@ -252,9 +253,9 @@
252253
"@babel/traverse": "7.22.5",
253254
"@types/react": "18.2.74",
254255
"@types/react-dom": "18.2.23",
255-
"react": "19.0.0-beta-4508873393-20240430",
256-
"react-dom": "19.0.0-beta-4508873393-20240430",
257-
"react-is": "19.0.0-beta-4508873393-20240430",
256+
"react": "19.0.0-beta-04b058868c-20240508",
257+
"react-dom": "19.0.0-beta-04b058868c-20240508",
258+
"react-is": "19.0.0-beta-04b058868c-20240508",
258259
"scheduler": "0.25.0-beta-94eed63c49-20240425"
259260
},
260261
"engines": {

packages/create-next-app/templates/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ export const installTemplate = async ({
183183
* Default dependencies.
184184
*/
185185
dependencies: {
186-
react: "19.0.0-beta-4508873393-20240430",
187-
"react-dom": "19.0.0-beta-4508873393-20240430",
186+
react: "19.0.0-beta-04b058868c-20240508",
187+
"react-dom": "19.0.0-beta-04b058868c-20240508",
188188
next: version,
189189
},
190190
devDependencies: {},

packages/next/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@
104104
"peerDependencies": {
105105
"@opentelemetry/api": "^1.1.0",
106106
"@playwright/test": "^1.41.2",
107-
"babel-plugin-react-compiler": "*",
108-
"react": "19.0.0-beta-4508873393-20240430",
109-
"react-dom": "19.0.0-beta-4508873393-20240430",
110-
"sass": "^1.3.0"
107+
"react": "^19.0.0-0",
108+
"react-dom": "^19.0.0-0",
109+
"sass": "^1.3.0",
110+
"babel-plugin-react-compiler": "*"
111111
},
112112
"peerDependenciesMeta": {
113113
"babel-plugin-react-compiler": {

packages/next/src/compiled/react-dom/cjs/react-dom-client.development.js

Lines changed: 140 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@
1212

1313
if (process.env.NODE_ENV !== "production") {
1414
(function() {
15-
16-
'use strict';
17-
18-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
15+
'use strict';
1916
if (
2017
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
2118
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
2219
'function'
2320
) {
2421
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
2522
}
26-
var React = require("next/dist/compiled/react");
23+
var React = require("next/dist/compiled/react");
2724
var Scheduler = require("next/dist/compiled/scheduler");
2825
var ReactDOM = require('react-dom');
2926

@@ -241,6 +238,7 @@ var REACT_DEBUG_TRACING_MODE_TYPE = Symbol.for('react.debug_trace_mode');
241238
var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
242239
var REACT_LEGACY_HIDDEN_TYPE = Symbol.for('react.legacy_hidden');
243240
var REACT_TRACING_MARKER_TYPE = Symbol.for('react.tracing_marker');
241+
var REACT_MEMO_CACHE_SENTINEL = Symbol.for('react.memo_cache_sentinel');
244242
var MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
245243
var FAUX_ITERATOR_SYMBOL = '@@iterator';
246244
function getIteratorFn(maybeIterable) {
@@ -8782,6 +8780,11 @@ function extractEvents$1(dispatchQueue, domEventName, maybeTargetInst, nativeEve
87828780
var temp = submitter.ownerDocument.createElement('input');
87838781
temp.name = submitter.name;
87848782
temp.value = submitter.value;
8783+
8784+
if (form.id) {
8785+
temp.setAttribute('form', form.id);
8786+
}
8787+
87858788
submitter.parentNode.insertBefore(temp, submitter);
87868789
formData = new FormData(form);
87878790
temp.parentNode.removeChild(temp);
@@ -17386,7 +17389,8 @@ var createFunctionComponentUpdateQueue;
1738617389
return {
1738717390
lastEffect: null,
1738817391
events: null,
17389-
stores: null
17392+
stores: null,
17393+
memoCache: null
1739017394
};
1739117395
};
1739217396
}
@@ -17432,6 +17436,93 @@ function use(usable) {
1743217436
throw new Error('An unsupported type was passed to use(): ' + String(usable));
1743317437
}
1743417438

17439+
function useMemoCache(size) {
17440+
var memoCache = null; // Fast-path, load memo cache from wip fiber if already prepared
17441+
17442+
var updateQueue = currentlyRenderingFiber$1.updateQueue;
17443+
17444+
if (updateQueue !== null) {
17445+
memoCache = updateQueue.memoCache;
17446+
} // Otherwise clone from the current fiber
17447+
17448+
17449+
if (memoCache == null) {
17450+
var current = currentlyRenderingFiber$1.alternate;
17451+
17452+
if (current !== null) {
17453+
var currentUpdateQueue = current.updateQueue;
17454+
17455+
if (currentUpdateQueue !== null) {
17456+
var currentMemoCache = currentUpdateQueue.memoCache;
17457+
17458+
if (currentMemoCache != null) {
17459+
memoCache = {
17460+
// When enableNoCloningMemoCache is enabled, instead of treating the
17461+
// cache as copy-on-write, like we do with fibers, we share the same
17462+
// cache instance across all render attempts, even if the component
17463+
// is interrupted before it commits.
17464+
//
17465+
// If an update is interrupted, either because it suspended or
17466+
// because of another update, we can reuse the memoized computations
17467+
// from the previous attempt. We can do this because the React
17468+
// Compiler performs atomic writes to the memo cache, i.e. it will
17469+
// not record the inputs to a memoization without also recording its
17470+
// output.
17471+
//
17472+
// This gives us a form of "resuming" within components and hooks.
17473+
//
17474+
// This only works when updating a component that already mounted.
17475+
// It has no impact during initial render, because the memo cache is
17476+
// stored on the fiber, and since we have not implemented resuming
17477+
// for fibers, it's always a fresh memo cache, anyway.
17478+
//
17479+
// However, this alone is pretty useful — it happens whenever you
17480+
// update the UI with fresh data after a mutation/action, which is
17481+
// extremely common in a Suspense-driven (e.g. RSC or Relay) app.
17482+
data: // Clone the memo cache before each render (copy-on-write)
17483+
currentMemoCache.data.map(function (array) {
17484+
return array.slice();
17485+
}),
17486+
index: 0
17487+
};
17488+
}
17489+
}
17490+
}
17491+
} // Finally fall back to allocating a fresh instance of the cache
17492+
17493+
17494+
if (memoCache == null) {
17495+
memoCache = {
17496+
data: [],
17497+
index: 0
17498+
};
17499+
}
17500+
17501+
if (updateQueue === null) {
17502+
updateQueue = createFunctionComponentUpdateQueue();
17503+
currentlyRenderingFiber$1.updateQueue = updateQueue;
17504+
}
17505+
17506+
updateQueue.memoCache = memoCache;
17507+
var data = memoCache.data[memoCache.index];
17508+
17509+
if (data === undefined) {
17510+
data = memoCache.data[memoCache.index] = new Array(size);
17511+
17512+
for (var i = 0; i < size; i++) {
17513+
data[i] = REACT_MEMO_CACHE_SENTINEL;
17514+
}
17515+
} else if (data.length !== size) {
17516+
// TODO: consider warning or throwing here
17517+
{
17518+
error('Expected a constant size argument for each invocation of useMemoCache. ' + 'The previous cache was allocated with size %s but size %s was requested.', data.length, size);
17519+
}
17520+
}
17521+
17522+
memoCache.index++;
17523+
return data;
17524+
}
17525+
1743517526
function basicStateReducer(state, action) {
1743617527
// $FlowFixMe[incompatible-use]: Flow doesn't like mixed types
1743717528
return typeof action === 'function' ? action(state) : action;
@@ -19230,6 +19321,10 @@ var ContextOnlyDispatcher = {
1923019321
ContextOnlyDispatcher.useCacheRefresh = throwInvalidHookError;
1923119322
}
1923219323

19324+
{
19325+
ContextOnlyDispatcher.useMemoCache = throwInvalidHookError;
19326+
}
19327+
1923319328
{
1923419329
ContextOnlyDispatcher.useHostTransitionStatus = throwInvalidHookError;
1923519330
ContextOnlyDispatcher.useFormState = throwInvalidHookError;
@@ -19374,6 +19469,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1937419469
};
1937519470
}
1937619471

19472+
{
19473+
HooksDispatcherOnMountInDEV.useMemoCache = useMemoCache;
19474+
}
19475+
1937719476
{
1937819477
HooksDispatcherOnMountInDEV.useHostTransitionStatus = useHostTransitionStatus;
1937919478

@@ -19509,6 +19608,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1950919608
};
1951019609
}
1951119610

19611+
{
19612+
HooksDispatcherOnMountWithHookTypesInDEV.useMemoCache = useMemoCache;
19613+
}
19614+
1951219615
{
1951319616
HooksDispatcherOnMountWithHookTypesInDEV.useHostTransitionStatus = useHostTransitionStatus;
1951419617

@@ -19645,6 +19748,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1964519748
};
1964619749
}
1964719750

19751+
{
19752+
HooksDispatcherOnUpdateInDEV.useMemoCache = useMemoCache;
19753+
}
19754+
1964819755
{
1964919756
HooksDispatcherOnUpdateInDEV.useHostTransitionStatus = useHostTransitionStatus;
1965019757

@@ -19781,6 +19888,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1978119888
};
1978219889
}
1978319890

19891+
{
19892+
HooksDispatcherOnRerenderInDEV.useMemoCache = useMemoCache;
19893+
}
19894+
1978419895
{
1978519896
HooksDispatcherOnRerenderInDEV.useHostTransitionStatus = useHostTransitionStatus;
1978619897

@@ -19936,6 +20047,13 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
1993620047
};
1993720048
}
1993820049

20050+
{
20051+
InvalidNestedHooksDispatcherOnMountInDEV.useMemoCache = function (size) {
20052+
warnInvalidHookAccess();
20053+
return useMemoCache(size);
20054+
};
20055+
}
20056+
1993920057
{
1994020058
InvalidNestedHooksDispatcherOnMountInDEV.useHostTransitionStatus = useHostTransitionStatus;
1994120059

@@ -20093,6 +20211,13 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
2009320211
};
2009420212
}
2009520213

20214+
{
20215+
InvalidNestedHooksDispatcherOnUpdateInDEV.useMemoCache = function (size) {
20216+
warnInvalidHookAccess();
20217+
return useMemoCache(size);
20218+
};
20219+
}
20220+
2009620221
{
2009720222
InvalidNestedHooksDispatcherOnUpdateInDEV.useHostTransitionStatus = useHostTransitionStatus;
2009820223

@@ -20250,6 +20375,13 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
2025020375
};
2025120376
}
2025220377

20378+
{
20379+
InvalidNestedHooksDispatcherOnRerenderInDEV.useMemoCache = function (size) {
20380+
warnInvalidHookAccess();
20381+
return useMemoCache(size);
20382+
};
20383+
}
20384+
2025320385
{
2025420386
InvalidNestedHooksDispatcherOnRerenderInDEV.useHostTransitionStatus = useHostTransitionStatus;
2025520387

@@ -35828,7 +35960,7 @@ identifierPrefix, onUncaughtError, onCaughtError, onRecoverableError, transition
3582835960
return root;
3582935961
}
3583035962

35831-
var ReactVersion = '19.0.0-beta-4508873393-20240430';
35963+
var ReactVersion = '19.0.0-beta-04b058868c-20240508';
3583235964

3583335965
// Might add PROFILE later.
3583435966

@@ -37328,14 +37460,13 @@ var foundDevTools = injectIntoDevTools({
3732837460
exports.createRoot = createRoot;
3732937461
exports.hydrateRoot = hydrateRoot;
3733037462
exports.version = ReactVersion;
37331-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
3733237463
if (
3733337464
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
3733437465
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
3733537466
'function'
3733637467
) {
3733737468
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
3733837469
}
37339-
37470+
3734037471
})();
3734137472
}

0 commit comments

Comments
 (0)