Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
[ghstack-poisoned]
  • Loading branch information
poteto committed Jul 1, 2024
2 parents 9df58ef + 5ab109f commit 4068d7d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
4 changes: 2 additions & 2 deletions fixtures/flight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"predev": "cp -r ../../build/oss-experimental/* ./node_modules/",
"prebuild": "cp -r ../../build/oss-experimental/* ./node_modules/",
"dev": "concurrently \"npm run dev:region\" \"npm run dev:global\"",
"dev:global": "NODE_ENV=development BUILD_PATH=dist node --experimental-loader ./loader/global.js server/global",
"dev:region": "NODE_ENV=development BUILD_PATH=dist nodemon --watch src --watch dist -- --enable-source-maps --experimental-loader ./loader/region.js --conditions=react-server server/region",
"dev:global": "NODE_ENV=development BUILD_PATH=dist node --experimental-loader ./loader/global.js --inspect=127.0.0.1:9230 server/global",
"dev:region": "NODE_ENV=development BUILD_PATH=dist nodemon --watch src --watch dist -- --enable-source-maps --experimental-loader ./loader/region.js --conditions=react-server --inspect=127.0.0.1:9229 server/region",
"start": "node scripts/build.js && concurrently \"npm run start:region\" \"npm run start:global\"",
"start:global": "NODE_ENV=production node --experimental-loader ./loader/global.js server/global",
"start:region": "NODE_ENV=production node --experimental-loader ./loader/region.js --conditions=react-server server/region",
Expand Down
39 changes: 39 additions & 0 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ import {
disableDefaultPropsExceptForClasses,
enableAsyncIterableChildren,
disableStringRefs,
enableOwnerStacks,
} from 'shared/ReactFeatureFlags';

import assign from 'shared/assign';
Expand Down Expand Up @@ -2372,6 +2373,27 @@ function renderNodeDestructive(
key == null ? (childIndex === -1 ? 0 : childIndex) : key;
const keyPath = [task.keyPath, name, keyOrIndex];
if (task.replay !== null) {
if (__DEV__ && enableOwnerStacks) {
const debugTask: null | ConsoleTask = element._debugTask;
if (debugTask) {
debugTask.run(
replayElement.bind(
null,
request,
task,
keyPath,
name,
keyOrIndex,
childIndex,
type,
props,
ref,
task.replay,
),
);
return;
}
}
replayElement(
request,
task,
Expand All @@ -2388,6 +2410,23 @@ function renderNodeDestructive(
// prelude and skip it during the replay.
} else {
// We're doing a plain render.
if (__DEV__ && enableOwnerStacks) {
const debugTask: null | ConsoleTask = element._debugTask;
if (debugTask) {
debugTask.run(
renderElement.bind(
null,
request,
task,
keyPath,
type,
props,
ref,
),
);
return;
}
}
renderElement(request, task, keyPath, type, props, ref);
}
return;
Expand Down
42 changes: 39 additions & 3 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function getStack(error: Error): string {

function initCallComponentFrame(): string {
// Extract the stack frame of the callComponentInDEV function.
const error = callComponentInDEV(Error, 'react-stack-top-frame', {});
const error = callComponentInDEV(Error, 'react-stack-top-frame', {}, null);
const stack = getStack(error);
const startIdx = stack.startsWith('Error: react-stack-top-frame\n') ? 29 : 0;
const endIdx = stack.indexOf('\n', startIdx);
Expand Down Expand Up @@ -991,20 +991,36 @@ function callComponentInDEV<Props, R>(
Component: (p: Props, arg: void) => R,
props: Props,
componentDebugInfo: ReactComponentInfo,
debugTask: null | ConsoleTask,
): R {
// The secondArg is always undefined in Server Components since refs error early.
const secondArg = undefined;
setCurrentOwner(componentDebugInfo);
try {
if (supportsComponentStorage) {
// Run the component in an Async Context that tracks the current owner.
if (enableOwnerStacks && debugTask) {
return debugTask.run(
// $FlowFixMe[method-unbinding]
componentStorage.run.bind(
componentStorage,
componentDebugInfo,
Component,
props,
secondArg,
),
);
}
return componentStorage.run(
componentDebugInfo,
Component,
props,
secondArg,
);
} else {
if (enableOwnerStacks && debugTask) {
return debugTask.run(Component.bind(null, props, secondArg));
}
return Component(props, secondArg);
}
} finally {
Expand All @@ -1028,6 +1044,7 @@ function renderFunctionComponent<Props>(
props: Props,
owner: null | ReactComponentInfo, // DEV-only
stack: null | string, // DEV-only
debugTask: null | ConsoleTask, // DEV-only
validated: number, // DEV-only
): ReactJSONValue {
// Reset the task's thenable state before continuing, so that if a later
Expand Down Expand Up @@ -1075,11 +1092,22 @@ function renderFunctionComponent<Props>(
task.environmentName = componentEnv;

if (enableOwnerStacks) {
warnForMissingKey(request, key, validated, componentDebugInfo);
warnForMissingKey(
request,
key,
validated,
componentDebugInfo,
debugTask,
);
}
}
prepareToUseHooksForComponent(prevThenableState, componentDebugInfo);
result = callComponentInDEV(Component, props, componentDebugInfo);
result = callComponentInDEV(
Component,
props,
componentDebugInfo,
debugTask,
);
} else {
prepareToUseHooksForComponent(prevThenableState, null);
// The secondArg is always undefined in Server Components since refs error early.
Expand Down Expand Up @@ -1235,6 +1263,7 @@ function warnForMissingKey(
key: null | string,
validated: number,
componentDebugInfo: ReactComponentInfo,
debugTask: null | ConsoleTask,
): void {
if (__DEV__) {
if (validated !== 2) {
Expand Down Expand Up @@ -1267,6 +1296,7 @@ function warnForMissingKey(
},
null,
componentDebugInfo,
debugTask,
);
}
}
Expand Down Expand Up @@ -1482,6 +1512,7 @@ function renderElement(
props: any,
owner: null | ReactComponentInfo, // DEV only
stack: null | string, // DEV only
debugTask: null | ConsoleTask, // DEV only
validated: number, // DEV only
): ReactJSONValue {
if (ref !== null && ref !== undefined) {
Expand Down Expand Up @@ -1514,6 +1545,7 @@ function renderElement(
props,
owner,
stack,
debugTask,
validated,
);
} else if (type === REACT_FRAGMENT_TYPE && key === null) {
Expand Down Expand Up @@ -1562,6 +1594,7 @@ function renderElement(
props,
owner,
stack,
debugTask,
validated,
);
}
Expand All @@ -1574,6 +1607,7 @@ function renderElement(
props,
owner,
stack,
debugTask,
validated,
);
}
Expand All @@ -1587,6 +1621,7 @@ function renderElement(
props,
owner,
stack,
debugTask,
validated,
);
}
Expand Down Expand Up @@ -2190,6 +2225,7 @@ function renderModelDestructive(
? element._debugStack
: filterDebugStack(element._debugStack)
: null,
__DEV__ && enableOwnerStacks ? element._debugTask : null,
__DEV__ && enableOwnerStacks ? element._store.validated : 0,
);
if (
Expand Down

0 comments on commit 4068d7d

Please sign in to comment.