Skip to content

Commit 82dccae

Browse files
committed
Run console.createTask during SSR when available
This is rarely used but it does allow seeing component stacks when inspecting the Node.js server running Fizz using --inspect and the Chrome DevTools.
1 parent 2e72ea8 commit 82dccae

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

fixtures/flight/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"predev": "cp -r ../../build/oss-experimental/* ./node_modules/",
7171
"prebuild": "cp -r ../../build/oss-experimental/* ./node_modules/",
7272
"dev": "concurrently \"npm run dev:region\" \"npm run dev:global\"",
73-
"dev:global": "NODE_ENV=development BUILD_PATH=dist node --experimental-loader ./loader/global.js server/global",
73+
"dev:global": "NODE_ENV=development BUILD_PATH=dist node --experimental-loader ./loader/global.js --inspect server/global",
7474
"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",
7575
"start": "node scripts/build.js && concurrently \"npm run start:region\" \"npm run start:global\"",
7676
"start:global": "NODE_ENV=production node --experimental-loader ./loader/global.js server/global",

fixtures/flight/src/Container.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22

33
export default function Container({children}) {
4+
console.error('hello world');
45
return <div>{children}</div>;
56
}

packages/react-server/src/ReactFizzServer.js

+39
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ import {
150150
disableDefaultPropsExceptForClasses,
151151
enableAsyncIterableChildren,
152152
disableStringRefs,
153+
enableOwnerStacks,
153154
} from 'shared/ReactFeatureFlags';
154155

155156
import assign from 'shared/assign';
@@ -2372,6 +2373,27 @@ function renderNodeDestructive(
23722373
key == null ? (childIndex === -1 ? 0 : childIndex) : key;
23732374
const keyPath = [task.keyPath, name, keyOrIndex];
23742375
if (task.replay !== null) {
2376+
if (__DEV__ && enableOwnerStacks) {
2377+
const debugTask: null | ConsoleTask = element._debugTask;
2378+
if (debugTask) {
2379+
debugTask.run(
2380+
replayElement.bind(
2381+
null,
2382+
request,
2383+
task,
2384+
keyPath,
2385+
name,
2386+
keyOrIndex,
2387+
childIndex,
2388+
type,
2389+
props,
2390+
ref,
2391+
task.replay,
2392+
),
2393+
);
2394+
return;
2395+
}
2396+
}
23752397
replayElement(
23762398
request,
23772399
task,
@@ -2388,6 +2410,23 @@ function renderNodeDestructive(
23882410
// prelude and skip it during the replay.
23892411
} else {
23902412
// We're doing a plain render.
2413+
if (__DEV__ && enableOwnerStacks) {
2414+
const debugTask: null | ConsoleTask = element._debugTask;
2415+
if (debugTask) {
2416+
debugTask.run(
2417+
renderElement.bind(
2418+
null,
2419+
request,
2420+
task,
2421+
keyPath,
2422+
type,
2423+
props,
2424+
ref,
2425+
),
2426+
);
2427+
return;
2428+
}
2429+
}
23912430
renderElement(request, task, keyPath, type, props, ref);
23922431
}
23932432
return;

packages/shared/ReactVersion.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
/**
2-
* Copyright (c) Meta Platforms, Inc. and affiliates.
3-
*
4-
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
6-
*/
7-
8-
// TODO: this is special because it gets imported during build.
9-
//
10-
// It exists as a placeholder so that DevTools can support work tag changes between releases.
11-
// When we next publish a release, update the matching TODO in backend/renderer.js
12-
// TODO: This module is used both by the release scripts and to expose a version
13-
// at runtime. We should instead inject the version number as part of the build
14-
// process, and use the ReactVersions.js module as the single source of truth.
15-
export default '19.0.0';
1+
export default '19.0.0-rc-a721388f4c-20240629';

0 commit comments

Comments
 (0)