Unverified Commit c6fe3f32 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Update app dir react for client reference updates (#45490)

x-ref: https://github.com/facebook/react/pull/26059
x-ref: https://github.com/facebook/react/pull/26083
x-ref: https://github.com/facebook/react/pull/26093
x-ref: https://github.com/facebook/react/pull/26083
Closes NEXT-445

* Remove extra `await`
* Check if a component result is client reference, then we access for
other exports
parent 25dfdbb1
......@@ -189,11 +189,11 @@
"random-seed": "0.3.0",
"react": "18.2.0",
"react-17": "npm:react@17.0.2",
"react-builtin": "npm:react@18.3.0-next-3ba7add60-20221201",
"react-builtin": "npm:react@18.3.0-next-4bf2113a1-20230206",
"react-dom": "18.2.0",
"react-dom-17": "npm:react-dom@17.0.2",
"react-dom-builtin": "npm:react-dom@18.3.0-next-3ba7add60-20221201",
"react-server-dom-webpack": "18.3.0-next-3ba7add60-20221201",
"react-dom-builtin": "npm:react-dom@18.3.0-next-4bf2113a1-20230206",
"react-server-dom-webpack": "18.3.0-next-4bf2113a1-20230206",
"react-ssr-prepass": "1.0.8",
"react-virtualized": "9.22.3",
"relay-compiler": "13.0.2",
......
export function isClientReference(reference: any): boolean {
return reference?.$$typeof === Symbol.for('react.client.reference')
}
......@@ -53,6 +53,7 @@ import {
overrideBuiltInReactPackages,
} from './webpack/require-hook'
import { AssetBinding } from './webpack/loaders/get-module-build-info'
import { isClientReference } from './is-client-reference'
loadRequireHook()
if (process.env.NEXT_PREBUNDLED_REACT) {
......@@ -1100,14 +1101,18 @@ export const collectGenerateParams = async (
: segment[2]?.page?.[0]?.())
const config = collectAppConfig(mod)
const isClientComponent = isClientReference(mod)
const result = {
isLayout,
segmentPath: `/${parentSegments.join('/')}${
segment[0] && parentSegments.length > 0 ? '/' : ''
}${segment[0]}`,
config,
getStaticPaths: mod?.getStaticPaths,
generateStaticParams: mod?.generateStaticParams,
getStaticPaths: isClientComponent ? undefined : mod?.getStaticPaths,
generateStaticParams: isClientComponent
? undefined
: mod?.generateStaticParams,
}
if (segment[0]) {
......@@ -1269,6 +1274,7 @@ export async function isPageStatic({
let encodedPrerenderRoutes: Array<string> | undefined
let prerenderFallback: boolean | 'blocking' | undefined
let appConfig: AppConfig = {}
let isClientComponent: boolean = false
if (isEdgeRuntime(pageRuntime)) {
const runtime = await getRuntimeContext({
......@@ -1288,6 +1294,7 @@ export async function isPageStatic({
const mod =
runtime.context._ENTRIES[`middleware_${edgeInfo.name}`].ComponentMod
isClientComponent = isClientReference(mod)
componentsResult = {
Component: mod.default,
ComponentMod: mod,
......@@ -1313,6 +1320,7 @@ export async function isPageStatic({
| undefined
if (pageType === 'app') {
isClientComponent = isClientReference(componentsResult.ComponentMod)
const tree = componentsResult.ComponentMod.tree
const generateParams = await collectGenerateParams(tree)
......@@ -1458,7 +1466,10 @@ export async function isPageStatic({
}
const isNextImageImported = (globalThis as any).__NEXT_IMAGE_IMPORTED
const config: PageConfig = componentsResult.pageConfig
const config: PageConfig = isClientComponent
? {}
: componentsResult.pageConfig
return {
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
isHybridAmp: config.amp === 'hybrid',
......
......@@ -7,11 +7,11 @@
// Modified from https://github.com/facebook/react/blob/main/packages/react-server-dom-webpack/src/ReactFlightWebpackNodeRegister.js
const MODULE_REFERENCE = Symbol.for('react.module.reference')
const CLIENT_REFERENCE = Symbol.for('react.client.reference')
const PROMISE_PROTOTYPE = Promise.prototype
const proxyHandlers: ProxyHandler<object> = {
get: function (target: any, name: string, _receiver: any) {
const deepProxyHandlers = {
get: function (target: any, name: string, _receiver: ProxyHandler<any>) {
switch (name) {
// These names are read by the Flight runtime if you end up using the exports object.
case '$$typeof':
......@@ -28,61 +28,167 @@ const proxyHandlers: ProxyHandler<object> = {
// reference.
case 'defaultProps':
return undefined
// Avoid this attempting to be serialized.
case 'toJSON':
return undefined
case Symbol.toPrimitive.toString():
// @ts-ignore
return Object.prototype[Symbol.toPrimitive]
case 'Provider':
throw new Error(
`Cannot render a Client Context Provider on the Server. ` +
`Instead, you can export a Client Component wrapper ` +
`that itself renders a Client Context Provider.`
)
default:
break
}
let expression
switch (target.name) {
case '':
expression = String(name)
break
case '*':
expression = String(name)
break
default:
expression = String(target.name) + '.' + String(name)
}
throw new Error(
`Cannot access ${expression} on the server. ` +
'You cannot dot into a client module from a server component. ' +
'You can only pass the imported name through.'
)
},
set: function () {
throw new Error('Cannot assign to a client module from a server module.')
},
}
const proxyHandlers = {
get: function (target: any, name: string, _receiver: ProxyHandler<any>) {
switch (name) {
// These names are read by the Flight runtime if you end up using the exports object.
case '$$typeof':
// These names are a little too common. We should probably have a way to
// have the Flight runtime extract the inner target instead.
return target.$$typeof
case 'filepath':
return target.filepath
case 'name':
return target.name
case 'async':
return target.async
// We need to special case this because createElement reads it if we pass this
// reference.
case 'defaultProps':
return undefined
// Avoid this attempting to be serialized.
case 'toJSON':
return undefined
case Symbol.toPrimitive.toString():
// @ts-ignore
return Object.prototype[Symbol.toPrimitive]
case '__esModule':
// Something is conditionally checking which export to use. We'll pretend to be
// an ESM compat module but then we'll check again on the client.
target.default = {
$$typeof: MODULE_REFERENCE,
filepath: target.filepath,
// This a placeholder value that tells the client to conditionally use the
// whole object or just the default export.
name: '',
async: target.async,
}
const moduleId = target.filepath
target.default = Object.defineProperties(
function () {
throw new Error(
`Attempted to call the default export of ${moduleId} from the server ` +
`but it's on the client. It's not possible to invoke a client function from ` +
`the server, it can only be rendered as a Component or passed to props of a ` +
`Client Component.`
)
},
{
// This a placeholder value that tells the client to conditionally use the
// whole object or just the default export.
name: { value: '' },
$$typeof: { value: CLIENT_REFERENCE },
filepath: { value: target.filepath },
async: { value: target.async },
}
)
return true
case 'then':
if (target.then) {
// Use a cached value
return target.then
}
if (!target.async) {
// If this module is expected to return a Promise (such as an AsyncModule) then
// we should resolve that with a client reference that unwraps the Promise on
// the client.
const then = function then(
resolve: (res: any) => void,
_reject: (err: any) => void
) {
const moduleReference: Record<string, any> = {
$$typeof: MODULE_REFERENCE,
filepath: target.filepath,
name: '*', // Represents the whole object instead of a particular import.
async: true,
const clientReference = Object.defineProperties(
{},
{
// Represents the whole Module object instead of a particular import.
name: { value: '*' },
$$typeof: { value: CLIENT_REFERENCE },
filepath: { value: target.filepath },
async: { value: true },
}
return Promise.resolve(
resolve(new Proxy(moduleReference, proxyHandlers))
)
}
// If this is not used as a Promise but is treated as a reference to a `.then`
// export then we should treat it as a reference to that name.
then.$$typeof = MODULE_REFERENCE
then.filepath = target.filepath
// then.name is conveniently already "then" which is the export name we need.
// This will break if it's minified though.
)
const proxy = new Proxy(clientReference, proxyHandlers)
// Treat this as a resolved Promise for React's use()
target.status = 'fulfilled'
target.value = proxy
const then = (target.then = Object.defineProperties(
function then(resolve: any, _reject: any) {
// Expose to React.
return Promise.resolve(
// $FlowFixMe[incompatible-call] found when upgrading Flow
resolve(proxy)
)
},
// If this is not used as a Promise but is treated as a reference to a `.then`
// export then we should treat it as a reference to that name.
{
name: { value: 'then' },
$$typeof: { value: CLIENT_REFERENCE },
filepath: { value: target.filepath },
async: { value: false },
}
))
return then
} else {
// Since typeof .then === 'function' is a feature test we'd continue recursing
// indefinitely if we return a function. Instead, we return an object reference
// if we check further.
return undefined
}
break
default:
break
}
let cachedReference = target[name]
if (!cachedReference) {
cachedReference = target[name] = {
$$typeof: MODULE_REFERENCE,
filepath: target.filepath,
name: name,
async: target.async,
}
const reference = Object.defineProperties(
function () {
throw new Error(
`Attempted to call ${String(name)}() from the server but ${String(
name
)} is on the client. ` +
`It's not possible to invoke a client function from the server, it can ` +
`only be rendered as a Component or passed to props of a Client Component.`
)
},
{
name: { value: name },
$$typeof: { value: CLIENT_REFERENCE },
filepath: { value: target.filepath },
async: { value: target.async },
}
)
cachedReference = target[name] = new Proxy(reference, deepProxyHandlers)
}
return cachedReference
},
getPrototypeOf(_target: object) {
getPrototypeOf(_target: any): object {
// Pretend to be a Promise in case anyone asks.
return PROMISE_PROTOTYPE
},
......@@ -92,11 +198,15 @@ const proxyHandlers: ProxyHandler<object> = {
}
export function createProxy(moduleId: string) {
const moduleReference = {
$$typeof: MODULE_REFERENCE,
filepath: moduleId,
name: '*', // Represents the whole object instead of a particular import.
async: false,
}
return new Proxy(moduleReference, proxyHandlers)
const clientReference = Object.defineProperties(
{},
{
// Represents the whole object instead of a particular import.
name: { value: '*' },
$$typeof: { value: CLIENT_REFERENCE },
filepath: { value: moduleId },
async: { value: false },
}
)
return new Proxy(clientReference, proxyHandlers)
}
......@@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';
var ReactVersion = '18.3.0-next-3ba7add60-20221201';
var ReactVersion = '18.3.0-next-4bf2113a1-20230206';
var Internals = {
usingClientEntryPoint: false,
......
......@@ -8,4 +8,4 @@
* LICENSE file in the root directory of this source tree.
*/
'use strict';var b={usingClientEntryPoint:!1,Events:null,Dispatcher:{current:null}};function d(a){for(var e="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)e+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+e+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=b;
exports.createPortal=function(){throw Error(d(448));};exports.flushSync=function(){throw Error(d(449));};exports.preinit=function(){var a=b.Dispatcher.current;a&&a.preinit.apply(this,arguments)};exports.preload=function(){var a=b.Dispatcher.current;a&&a.preload.apply(this,arguments)};exports.version="18.3.0-next-3ba7add60-20221201";
exports.createPortal=function(){throw Error(d(448));};exports.flushSync=function(){throw Error(d(449));};exports.preinit=function(){var a=b.Dispatcher.current;a&&a.preinit.apply(this,arguments)};exports.preload=function(){var a=b.Dispatcher.current;a&&a.preload.apply(this,arguments)};exports.version="18.3.0-next-4bf2113a1-20230206";
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -6,7 +6,7 @@ if (process.env.NODE_ENV === 'production') {
exports.hydrateRoot = m.hydrateRoot;
} else {
var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
exports.createRoot = function(c, o) {
exports.createRoot = function (c, o) {
i.usingClientEntryPoint = true;
try {
return m.createRoot(c, o);
......@@ -14,7 +14,7 @@ if (process.env.NODE_ENV === 'production') {
i.usingClientEntryPoint = false;
}
};
exports.hydrateRoot = function(c, h, o) {
exports.hydrateRoot = function (c, h, o) {
i.usingClientEntryPoint = true;
try {
return m.hydrateRoot(c, h, o);
......
{
"name": "react-dom",
"version": "18.3.0-next-3ba7add60-20221201",
"version": "18.3.0-next-4bf2113a1-20230206",
"description": "React package for working with the DOM.",
"main": "index.js",
"repository": {
......@@ -18,10 +18,10 @@
"homepage": "https://reactjs.org/",
"dependencies": {
"loose-envify": "^1.1.0",
"scheduler": "0.24.0-next-3ba7add60-20221201"
"scheduler": "0.24.0-next-4bf2113a1-20230206"
},
"peerDependencies": {
"react": "18.3.0-next-3ba7add60-20221201"
"react": "18.3.0-next-4bf2113a1-20230206"
},
"files": [
"LICENSE",
......
......@@ -102,7 +102,7 @@ var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in
var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
var REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
function isValidElementType(type) {
if (typeof type === 'string' || typeof type === 'function') {
return true;
......@@ -118,7 +118,7 @@ function isValidElementType(type) {
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
type.$$typeof === REACT_CLIENT_REFERENCE || type.getModuleId !== undefined) {
return true;
}
}
......@@ -968,6 +968,7 @@ function jsxDEV(type, config, maybeKey, source, self) {
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
var REACT_CLIENT_REFERENCE$1 = Symbol.for('react.client.reference');
function setCurrentlyValidatingElement$1(element) {
{
......@@ -1107,11 +1108,11 @@ function validateExplicitKey(element, parentType) {
function validateChildKeys(node, parentType) {
{
if (typeof node !== 'object') {
if (typeof node !== 'object' || !node) {
return;
}
if (isArray(node)) {
if (node.$$typeof === REACT_CLIENT_REFERENCE$1) ; else if (isArray(node)) {
for (var i = 0; i < node.length; i++) {
var child = node[i];
......@@ -1124,7 +1125,7 @@ function validateChildKeys(node, parentType) {
if (node._store) {
node._store.validated = true;
}
} else if (node) {
} else {
var iteratorFn = getIteratorFn(node);
if (typeof iteratorFn === 'function') {
......@@ -1160,6 +1161,10 @@ function validatePropTypes(element) {
return;
}
if (type.$$typeof === REACT_CLIENT_REFERENCE$1) {
return;
}
var propTypes;
if (typeof type === 'function') {
......@@ -1293,21 +1298,19 @@ function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
}
}
{
if (hasOwnProperty.call(props, 'key')) {
var componentName = getComponentNameFromType(type);
var keys = Object.keys(props).filter(function (k) {
return k !== 'key';
});
var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
if (hasOwnProperty.call(props, 'key')) {
var componentName = getComponentNameFromType(type);
var keys = Object.keys(props).filter(function (k) {
return k !== 'key';
});
var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
if (!didWarnAboutKeySpread[componentName + beforeExample]) {
var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
if (!didWarnAboutKeySpread[componentName + beforeExample]) {
var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
didWarnAboutKeySpread[componentName + beforeExample] = true;
}
didWarnAboutKeySpread[componentName + beforeExample] = true;
}
}
......
......@@ -102,7 +102,7 @@ var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in
var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
var REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
function isValidElementType(type) {
if (typeof type === 'string' || typeof type === 'function') {
return true;
......@@ -118,7 +118,7 @@ function isValidElementType(type) {
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
type.$$typeof === REACT_CLIENT_REFERENCE || type.getModuleId !== undefined) {
return true;
}
}
......@@ -968,6 +968,7 @@ function jsxDEV(type, config, maybeKey, source, self) {
var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
var REACT_CLIENT_REFERENCE$1 = Symbol.for('react.client.reference');
function setCurrentlyValidatingElement$1(element) {
{
......@@ -1107,11 +1108,11 @@ function validateExplicitKey(element, parentType) {
function validateChildKeys(node, parentType) {
{
if (typeof node !== 'object') {
if (typeof node !== 'object' || !node) {
return;
}
if (isArray(node)) {
if (node.$$typeof === REACT_CLIENT_REFERENCE$1) ; else if (isArray(node)) {
for (var i = 0; i < node.length; i++) {
var child = node[i];
......@@ -1124,7 +1125,7 @@ function validateChildKeys(node, parentType) {
if (node._store) {
node._store.validated = true;
}
} else if (node) {
} else {
var iteratorFn = getIteratorFn(node);
if (typeof iteratorFn === 'function') {
......@@ -1160,6 +1161,10 @@ function validatePropTypes(element) {
return;
}
if (type.$$typeof === REACT_CLIENT_REFERENCE$1) {
return;
}
var propTypes;
if (typeof type === 'function') {
......@@ -1293,21 +1298,19 @@ function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
}
}
{
if (hasOwnProperty.call(props, 'key')) {
var componentName = getComponentNameFromType(type);
var keys = Object.keys(props).filter(function (k) {
return k !== 'key';
});
var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
if (hasOwnProperty.call(props, 'key')) {
var componentName = getComponentNameFromType(type);
var keys = Object.keys(props).filter(function (k) {
return k !== 'key';
});
var beforeExample = keys.length > 0 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}' : '{key: someKey}';
if (!didWarnAboutKeySpread[componentName + beforeExample]) {
var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
if (!didWarnAboutKeySpread[componentName + beforeExample]) {
var afterExample = keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
error('A props object containing a "key" prop is being spread into JSX:\n' + ' let props = %s;\n' + ' <%s {...props} />\n' + 'React keys must be passed directly to JSX without using spread:\n' + ' let props = %s;\n' + ' <%s key={someKey} {...props} />', beforeExample, componentName, afterExample, componentName);
didWarnAboutKeySpread[componentName + beforeExample] = true;
}
didWarnAboutKeySpread[componentName + beforeExample] = true;
}
}
......
......@@ -23,7 +23,7 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var ReactVersion = '18.3.0-next-3ba7add60-20221201';
var ReactVersion = '18.3.0-next-4bf2113a1-20230206';
// ATTENTION
// When adding new symbols to this file,
......@@ -108,8 +108,7 @@ var ReactCurrentOwner = {
current: null
};
var ReactDebugCurrentFrame = // $FlowFixMe[incompatible-exact]
{};
var ReactDebugCurrentFrame = {};
var currentExtraStackFrame = null;
function setExtraStackFrame(stack) {
{
......@@ -1106,9 +1105,9 @@ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
mappedChild = cloneAndReplaceKey(mappedChild, // Keep both the (mapped) and old keys if they differ, just as
// traverseAllChildren used to do for objects as children
escapedPrefix + ( // $FlowFixMe Flow incorrectly thinks React.Portal doesn't have a key
mappedChild.key && (!_child || _child.key !== mappedChild.key) ? escapeUserProvidedKey( // eslint-disable-next-line react-internal/safe-string-coercion
'' + // $FlowFixMe Flow incorrectly thinks existing element's key can be a number
mappedChild.key) + '/' : '') + childKey);
mappedChild.key && (!_child || _child.key !== mappedChild.key) ? escapeUserProvidedKey( // $FlowFixMe[unsafe-addition]
'' + mappedChild.key // eslint-disable-line react-internal/safe-string-coercion
) + '/' : '') + childKey);
}
array.push(mappedChild);
......@@ -1164,7 +1163,6 @@ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
return subtreeCount;
}
/**
* Maps children that are typically specified as `props.children`.
*
......@@ -1178,6 +1176,8 @@ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
* @param {*} context Context for mapFunction.
* @return {object} Object containing the ordered map of results.
*/
function mapChildren(children, func, context) {
if (children == null) {
return children;
......@@ -1208,7 +1208,6 @@ function countChildren(children) {
});
return n;
}
/**
* Iterates through children that are typically specified as `props.children`.
*
......@@ -1221,8 +1220,11 @@ function countChildren(children) {
* @param {function(*, int)} forEachFunc
* @param {*} forEachContext Context for forEachContext.
*/
function forEachChildren(children, forEachFunc, forEachContext) {
mapChildren(children, function () {
mapChildren(children, // $FlowFixMe[missing-this-annot]
function () {
forEachFunc.apply(this, arguments); // Don't return anything.
}, forEachContext);
}
......@@ -1462,6 +1464,7 @@ function lazy(ctor) {
get: function () {
return defaultProps;
},
// $FlowFixMe[missing-local-annot]
set: function (newDefaultProps) {
error('React.lazy(...): It is not supported to assign `defaultProps` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
......@@ -1478,6 +1481,7 @@ function lazy(ctor) {
get: function () {
return propTypes;
},
// $FlowFixMe[missing-local-annot]
set: function (newPropTypes) {
error('React.lazy(...): It is not supported to assign `propTypes` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
......@@ -1546,7 +1550,7 @@ function forwardRef(render) {
return elementType;
}
var REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
function isValidElementType(type) {
if (typeof type === 'string' || typeof type === 'function') {
return true;
......@@ -1562,7 +1566,7 @@ function isValidElementType(type) {
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
type.$$typeof === REACT_CLIENT_REFERENCE || type.getModuleId !== undefined) {
return true;
}
}
......@@ -2225,6 +2229,8 @@ function checkPropTypes(typeSpecs, values, location, componentName, element) {
}
}
var REACT_CLIENT_REFERENCE$1 = Symbol.for('react.client.reference');
function setCurrentlyValidatingElement$1(element) {
{
if (element) {
......@@ -2350,11 +2356,11 @@ function validateExplicitKey(element, parentType) {
function validateChildKeys(node, parentType) {
if (typeof node !== 'object') {
if (typeof node !== 'object' || !node) {
return;
}
if (isArray(node)) {
if (node.$$typeof === REACT_CLIENT_REFERENCE$1) ; else if (isArray(node)) {
for (var i = 0; i < node.length; i++) {
var child = node[i];
......@@ -2367,7 +2373,7 @@ function validateChildKeys(node, parentType) {
if (node._store) {
node._store.validated = true;
}
} else if (node) {
} else {
var iteratorFn = getIteratorFn(node);
if (typeof iteratorFn === 'function') {
......@@ -2402,6 +2408,10 @@ function validatePropTypes(element) {
return;
}
if (type.$$typeof === REACT_CLIENT_REFERENCE$1) {
return;
}
var propTypes;
if (typeof type === 'function') {
......@@ -2654,11 +2664,11 @@ function startTransition(scope, options) {
if (prevTransition === null && currentTransition._updatedFibers) {
var updatedFibersCount = currentTransition._updatedFibers.size;
currentTransition._updatedFibers.clear();
if (updatedFibersCount > 10) {
warn('Detected a large number of updates inside startTransition. ' + 'If this is due to a subscription please re-write it to use React provided hooks. ' + 'Otherwise concurrent mode guarantees are off the table.');
}
currentTransition._updatedFibers.clear();
}
}
}
......
......@@ -27,4 +27,4 @@ exports.createServerContext=function(a,b){var d=!0;if(!Z[a]){d=!1;var c={$$typeo
exports.isValidElement=P;exports.lazy=function(a){return{$$typeof:z,_payload:{_status:-1,_result:a},_init:ba}};exports.memo=function(a,b){return{$$typeof:y,type:a,compare:void 0===b?null:b}};exports.startTransition=function(a){var b=X.transition;X.transition={};try{a()}finally{X.transition=b}};exports.unstable_act=function(){throw Error("act(...) is not supported in production builds of React.");};exports.unstable_useCacheRefresh=function(){return W.current.useCacheRefresh()};exports.use=function(a){return W.current.use(a)};
exports.useCallback=function(a,b){return W.current.useCallback(a,b)};exports.useContext=function(a){return W.current.useContext(a)};exports.useDebugValue=function(){};exports.useDeferredValue=function(a){return W.current.useDeferredValue(a)};exports.useEffect=function(a,b){return W.current.useEffect(a,b)};exports.useId=function(){return W.current.useId()};exports.useImperativeHandle=function(a,b,d){return W.current.useImperativeHandle(a,b,d)};
exports.useInsertionEffect=function(a,b){return W.current.useInsertionEffect(a,b)};exports.useLayoutEffect=function(a,b){return W.current.useLayoutEffect(a,b)};exports.useMemo=function(a,b){return W.current.useMemo(a,b)};exports.useReducer=function(a,b,d){return W.current.useReducer(a,b,d)};exports.useRef=function(a){return W.current.useRef(a)};exports.useState=function(a){return W.current.useState(a)};exports.useSyncExternalStore=function(a,b,d){return W.current.useSyncExternalStore(a,b,d)};
exports.useTransition=function(){return W.current.useTransition()};exports.version="18.3.0-next-3ba7add60-20221201";
exports.useTransition=function(){return W.current.useTransition()};exports.version="18.3.0-next-4bf2113a1-20230206";
......@@ -61,8 +61,7 @@ var ReactCurrentOwner = {
current: null
};
var ReactDebugCurrentFrame = // $FlowFixMe[incompatible-exact]
{};
var ReactDebugCurrentFrame = {};
var currentExtraStackFrame = null;
function setExtraStackFrame(stack) {
{
......@@ -303,7 +302,7 @@ function generateCacheKey(request) {
}
}
var ReactVersion = '18.3.0-next-3ba7add60-20221201';
var ReactVersion = '18.3.0-next-4bf2113a1-20230206';
// ATTENTION
// When adding new symbols to this file,
......@@ -1217,9 +1216,9 @@ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
mappedChild = cloneAndReplaceKey(mappedChild, // Keep both the (mapped) and old keys if they differ, just as
// traverseAllChildren used to do for objects as children
escapedPrefix + ( // $FlowFixMe Flow incorrectly thinks React.Portal doesn't have a key
mappedChild.key && (!_child || _child.key !== mappedChild.key) ? escapeUserProvidedKey( // eslint-disable-next-line react-internal/safe-string-coercion
'' + // $FlowFixMe Flow incorrectly thinks existing element's key can be a number
mappedChild.key) + '/' : '') + childKey);
mappedChild.key && (!_child || _child.key !== mappedChild.key) ? escapeUserProvidedKey( // $FlowFixMe[unsafe-addition]
'' + mappedChild.key // eslint-disable-line react-internal/safe-string-coercion
) + '/' : '') + childKey);
}
array.push(mappedChild);
......@@ -1275,7 +1274,6 @@ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
return subtreeCount;
}
/**
* Maps children that are typically specified as `props.children`.
*
......@@ -1289,6 +1287,8 @@ function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
* @param {*} context Context for mapFunction.
* @return {object} Object containing the ordered map of results.
*/
function mapChildren(children, func, context) {
if (children == null) {
return children;
......@@ -1319,7 +1319,6 @@ function countChildren(children) {
});
return n;
}
/**
* Iterates through children that are typically specified as `props.children`.
*
......@@ -1332,8 +1331,11 @@ function countChildren(children) {
* @param {function(*, int)} forEachFunc
* @param {*} forEachContext Context for forEachContext.
*/
function forEachChildren(children, forEachFunc, forEachContext) {
mapChildren(children, function () {
mapChildren(children, // $FlowFixMe[missing-this-annot]
function () {
forEachFunc.apply(this, arguments); // Don't return anything.
}, forEachContext);
}
......@@ -1459,6 +1461,7 @@ function lazy(ctor) {
get: function () {
return defaultProps;
},
// $FlowFixMe[missing-local-annot]
set: function (newDefaultProps) {
error('React.lazy(...): It is not supported to assign `defaultProps` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
......@@ -1475,6 +1478,7 @@ function lazy(ctor) {
get: function () {
return propTypes;
},
// $FlowFixMe[missing-local-annot]
set: function (newPropTypes) {
error('React.lazy(...): It is not supported to assign `propTypes` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
......@@ -1543,7 +1547,7 @@ function forwardRef(render) {
return elementType;
}
var REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
var REACT_CLIENT_REFERENCE = Symbol.for('react.client.reference');
function isValidElementType(type) {
if (typeof type === 'string' || typeof type === 'function') {
return true;
......@@ -1559,7 +1563,7 @@ function isValidElementType(type) {
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
type.$$typeof === REACT_CLIENT_REFERENCE || type.getModuleId !== undefined) {
return true;
}
}
......@@ -2177,6 +2181,8 @@ function checkPropTypes(typeSpecs, values, location, componentName, element) {
}
}
var REACT_CLIENT_REFERENCE$1 = Symbol.for('react.client.reference');
function setCurrentlyValidatingElement$1(element) {
{
if (element) {
......@@ -2302,11 +2308,11 @@ function validateExplicitKey(element, parentType) {
function validateChildKeys(node, parentType) {
if (typeof node !== 'object') {
if (typeof node !== 'object' || !node) {
return;
}
if (isArray(node)) {
if (node.$$typeof === REACT_CLIENT_REFERENCE$1) ; else if (isArray(node)) {
for (var i = 0; i < node.length; i++) {
var child = node[i];
......@@ -2319,7 +2325,7 @@ function validateChildKeys(node, parentType) {
if (node._store) {
node._store.validated = true;
}
} else if (node) {
} else {
var iteratorFn = getIteratorFn(node);
if (typeof iteratorFn === 'function') {
......@@ -2354,6 +2360,10 @@ function validatePropTypes(element) {
return;
}
if (type.$$typeof === REACT_CLIENT_REFERENCE$1) {
return;
}
var propTypes;
if (typeof type === 'function') {
......@@ -2578,11 +2588,11 @@ function startTransition(scope, options) {
if (prevTransition === null && currentTransition._updatedFibers) {
var updatedFibersCount = currentTransition._updatedFibers.size;
currentTransition._updatedFibers.clear();
if (updatedFibersCount > 10) {
warn('Detected a large number of updates inside startTransition. ' + 'If this is due to a subscription please re-write it to use React provided hooks. ' + 'Otherwise concurrent mode guarantees are off the table.');
}
currentTransition._updatedFibers.clear();
}
}
}
......
......@@ -26,4 +26,4 @@ exports.cloneElement=function(a,b,d){if(null===a||void 0===a)throw Error(F(267,a
key:e,ref:f,props:c,_owner:g}};exports.createElement=function(a,b,d){var c,e={},f=null,g=null;if(null!=b)for(c in void 0!==b.ref&&(g=b.ref),void 0!==b.key&&(f=""+b.key),b)N.call(b,c)&&!P.hasOwnProperty(c)&&(e[c]=b[c]);var h=arguments.length-2;if(1===h)e.children=d;else if(1<h){for(var k=Array(h),l=0;l<h;l++)k[l]=arguments[l+2];e.children=k}if(a&&a.defaultProps)for(c in h=a.defaultProps,h)void 0===e[c]&&(e[c]=h[c]);return{$$typeof:t,type:a,key:f,ref:g,props:e,_owner:O.current}};exports.createRef=function(){return{current:null}};
exports.createServerContext=function(a,b){var d=!0;if(!Z[a]){d=!1;var c={$$typeof:z,_currentValue:b,_currentValue2:b,_defaultValue:b,_threadCount:0,Provider:null,Consumer:null,_globalName:a};c.Provider={$$typeof:y,_context:c};Z[a]=c}c=Z[a];if(c._defaultValue===D)c._defaultValue=b,c._currentValue===D&&(c._currentValue=b),c._currentValue2===D&&(c._currentValue2=b);else if(d)throw Error(F(429,a));return c};exports.forwardRef=function(a){return{$$typeof:A,render:a}};exports.isValidElement=Q;
exports.lazy=function(a){return{$$typeof:aa,_payload:{_status:-1,_result:a},_init:da}};exports.memo=function(a,b){return{$$typeof:C,type:a,compare:void 0===b?null:b}};exports.startTransition=function(a){var b=X.transition;X.transition={};try{a()}finally{X.transition=b}};exports.use=function(a){return W.current.use(a)};exports.useCallback=function(a,b){return W.current.useCallback(a,b)};exports.useContext=function(a){return W.current.useContext(a)};exports.useDebugValue=function(){};
exports.useId=function(){return W.current.useId()};exports.useMemo=function(a,b){return W.current.useMemo(a,b)};exports.version="18.3.0-next-3ba7add60-20221201";
exports.useId=function(){return W.current.useId()};exports.useMemo=function(a,b){return W.current.useMemo(a,b)};exports.version="18.3.0-next-4bf2113a1-20230206";
......@@ -4,7 +4,7 @@
"keywords": [
"react"
],
"version": "18.3.0-next-3ba7add60-20221201",
"version": "18.3.0-next-4bf2113a1-20230206",
"homepage": "https://reactjs.org/",
"bugs": "https://github.com/facebook/react/issues",
"license": "MIT",
......
......@@ -16,6 +16,7 @@ import { createDefaultMetadata } from './default-metadata'
import { resolveOpenGraph } from './resolve-opengraph'
import { mergeTitle } from './resolve-title'
import { resolveAsArrayOrUndefined } from './generate/utils'
import { isClientReference } from '../../build/is-client-reference'
import {
getLayoutOrPageModule,
LoaderTree,
......@@ -340,10 +341,7 @@ async function getDefinedMetadata(
// Layer is a client component, we just skip it. It can't have metadata
// exported. Note that during our SWC transpilation, it should check if
// the exports are valid and give specific error messages.
if (
'$$typeof' in mod &&
(mod as any).$$typeof === Symbol.for('react.module.reference')
) {
if (isClientReference(mod)) {
return null
}
......
......@@ -51,6 +51,7 @@ import { runWithRequestAsyncStorage } from './run-with-request-async-storage'
import { runWithStaticGenerationAsyncStorage } from './run-with-static-generation-async-storage'
import { collectMetadata } from '../lib/metadata/resolve-metadata'
import type { MetadataItems } from '../lib/metadata/resolve-metadata'
import { isClientReference } from '../build/is-client-reference'
import { getLayoutOrPageModule, LoaderTree } from './lib/app-dir-module'
const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'
......@@ -1103,6 +1104,8 @@ export async function renderToHTMLOrFlight(
}
if (head) {
console.warn(`\`head.js\` is deprecated, please use`)
const Head = await interopDefault(await head[0]())
return [<Head params={currentParams} />, metadataItems]
}
......@@ -1188,7 +1191,8 @@ export async function renderToHTMLOrFlight(
/>
))
: null
const Comp = await interopDefault(await getComponent())
const Comp = interopDefault(await getComponent())
return [Comp, styles]
}
......@@ -1361,7 +1365,10 @@ export async function renderToHTMLOrFlight(
)
}
if (layoutOrPageMod?.config?.amp) {
if (
!isClientReference(layoutOrPageMod) &&
layoutOrPageMod?.config?.amp
) {
throw new Error(
'AMP is not supported in the app directory. If you need to use AMP it will continue to be supported in the pages directory.'
)
......@@ -1504,9 +1511,11 @@ export async function renderToHTMLOrFlight(
}
// Eagerly execute layout/page component to trigger fetches early.
Component = await Promise.resolve().then(() => {
return preloadComponent(Component, props)
})
if (!isClientReference(layoutOrPageMod)) {
Component = await Promise.resolve().then(() =>
preloadComponent(Component, props)
)
}
return {
Component: () => {
......
......@@ -150,11 +150,11 @@ importers:
random-seed: 0.3.0
react: 18.2.0
react-17: npm:react@17.0.2
react-builtin: npm:react@18.3.0-next-3ba7add60-20221201
react-builtin: npm:react@18.3.0-next-4bf2113a1-20230206
react-dom: 18.2.0
react-dom-17: npm:react-dom@17.0.2
react-dom-builtin: npm:react-dom@18.3.0-next-3ba7add60-20221201
react-server-dom-webpack: 18.3.0-next-3ba7add60-20221201
react-dom-builtin: npm:react-dom@18.3.0-next-4bf2113a1-20230206
react-server-dom-webpack: 18.3.0-next-4bf2113a1-20230206
react-ssr-prepass: 1.0.8
react-virtualized: 9.22.3
relay-compiler: 13.0.2
......@@ -325,11 +325,11 @@ importers:
random-seed: 0.3.0
react: 18.2.0
react-17: /react/17.0.2
react-builtin: /react/18.3.0-next-3ba7add60-20221201
react-builtin: /react/18.3.0-next-4bf2113a1-20230206
react-dom: 18.2.0_react@18.2.0
react-dom-17: /react-dom/17.0.2_react@18.2.0
react-dom-builtin: /react-dom/18.3.0-next-3ba7add60-20221201_react@18.2.0
react-server-dom-webpack: 18.3.0-next-3ba7add60-20221201_4ifzx734of5j5ymg4ksx54vtqi
react-dom-builtin: /react-dom/18.3.0-next-4bf2113a1-20230206_react@18.2.0
react-server-dom-webpack: 18.3.0-next-4bf2113a1-20230206_4ifzx734of5j5ymg4ksx54vtqi
react-ssr-prepass: 1.0.8_qncsgtzehe3fgiqp6tr7lwq6fm
react-virtualized: 9.22.3_biqbaboplfbrettd7655fr4n2y
relay-compiler: 13.0.2
......@@ -19883,14 +19883,14 @@ packages:
react: 18.2.0
scheduler: 0.23.0
/react-dom/18.3.0-next-3ba7add60-20221201_react@18.2.0:
resolution: {integrity: sha512-v9XF5iF4r/6Ijcsn4TgF1ZNq5EbuLRQDUyq8FRamBWTbrjbA7lXWdpN6qRU+eBVgT5zxiBdL4ZCC/a+7bgMIYA==}
/react-dom/18.3.0-next-4bf2113a1-20230206_react@18.2.0:
resolution: {integrity: sha512-ZhRBPosy2OyQaYB/gLgmV23fX2+m3b4f3qrnAKLsFgVRPHkkafHtUb53I/7jfnuLseUgY0uqHH9L2CyARYfzEw==}
peerDependencies:
react: 18.3.0-next-3ba7add60-20221201
react: 18.3.0-next-4bf2113a1-20230206
dependencies:
loose-envify: 1.4.0
react: 18.2.0
scheduler: 0.24.0-next-3ba7add60-20221201
scheduler: 0.24.0-next-4bf2113a1-20230206
dev: true
/react-is/16.13.1:
......@@ -19913,12 +19913,12 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
/react-server-dom-webpack/18.3.0-next-3ba7add60-20221201_4ifzx734of5j5ymg4ksx54vtqi:
resolution: {integrity: sha512-liCl8Yyr+zQ5kTRKwCS1c6NMat0JCcIp0/evNcm0GymwLBXaaENnwthcEq2HpChI7j8TcOoscQ2zn6z3Lrew5A==}
/react-server-dom-webpack/18.3.0-next-4bf2113a1-20230206_4ifzx734of5j5ymg4ksx54vtqi:
resolution: {integrity: sha512-Bf9AcbE2k0ujuFbvcfUQC05Xnr2WhIjtxboaz5rTWWvkjmoX7Rj9c5YXradGHkxSsLx86BPoTvUUFFES6qGE7g==}
engines: {node: '>=0.10.0'}
peerDependencies:
react: 18.3.0-next-3ba7add60-20221201
react-dom: 18.3.0-next-3ba7add60-20221201
react: 18.3.0-next-4bf2113a1-20230206
react-dom: 18.3.0-next-4bf2113a1-20230206
webpack: ^5.59.0
dependencies:
acorn: 6.4.2
......@@ -19969,8 +19969,8 @@ packages:
dependencies:
loose-envify: 1.4.0
/react/18.3.0-next-3ba7add60-20221201:
resolution: {integrity: sha512-/hwADSpnz/GeDEljbg7Z2mF2MaYw7V1CsdbGvvhCUse4RvaRueHjcH7B/jbik8wRll3rxBPlomt15rSjIMjEJQ==}
/react/18.3.0-next-4bf2113a1-20230206:
resolution: {integrity: sha512-dXmfVmkxw+wsy7uMUTGeClhbqVm6TKOB2vqxoqsNJH8BL+763Ko63m1Aoz36gcnw9W6lZxmVAwFdmu9yxls41A==}
engines: {node: '>=0.10.0'}
dependencies:
loose-envify: 1.4.0
......@@ -21020,8 +21020,8 @@ packages:
dependencies:
loose-envify: 1.4.0
/scheduler/0.24.0-next-3ba7add60-20221201:
resolution: {integrity: sha512-AF0rxaEU3vzEatNQORHkPwzYU8ZkVEcQA240QddSriy4rI35vzaRr1xs/fv7KPVTL1bwZlcu088cp80UOsUeWQ==}
/scheduler/0.24.0-next-4bf2113a1-20230206:
resolution: {integrity: sha512-B2+m9CzYPNeQgHKudkSFTVxEjFsLioaJO85tpND9kntJ1aOLkR0/qgBItNZyVUoz5TkwWFn4r9v9hN6ChsA6pQ==}
dependencies:
loose-envify: 1.4.0
dev: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment