Skip to content

Commit c4c5e0f

Browse files
committed
Add environmentName option
This lets you name the server that is producing the debug info so that you can trace the origin of where that component is executing.
1 parent ec33294 commit c4c5e0f

File tree

15 files changed

+56
-17
lines changed

15 files changed

+56
-17
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const INITIALIZED = 'fulfilled';
7777
const ERRORED = 'rejected';
7878

7979
// Dev-only
80-
type ReactDebugInfo = Array<{+name?: string}>;
80+
type ReactDebugInfo = Array<{+name?: string, +env?: string}>;
8181

8282
type PendingChunk<T> = {
8383
status: 'pending',

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('ReactFlight', () => {
187187
const rootModel = await ReactNoopFlightClient.read(transport);
188188
const greeting = rootModel.greeting;
189189
expect(greeting._debugInfo).toEqual(
190-
__DEV__ ? [{name: 'Greeting'}] : undefined,
190+
__DEV__ ? [{name: 'Greeting', env: 'server'}] : undefined,
191191
);
192192
ReactNoop.render(greeting);
193193
});
@@ -214,7 +214,7 @@ describe('ReactFlight', () => {
214214
await act(async () => {
215215
const promise = ReactNoopFlightClient.read(transport);
216216
expect(promise._debugInfo).toEqual(
217-
__DEV__ ? [{name: 'Greeting'}] : undefined,
217+
__DEV__ ? [{name: 'Greeting', env: 'server'}] : undefined,
218218
);
219219
ReactNoop.render(await promise);
220220
});
@@ -1826,9 +1826,14 @@ describe('ReactFlight', () => {
18261826
return <div>Hello, {children}</div>;
18271827
}
18281828

1829-
const promise = Promise.resolve(<ThirdPartyComponent />);
1829+
const promiseComponent = Promise.resolve(<ThirdPartyComponent />);
18301830

1831-
const thirdPartyTransport = ReactNoopFlightServer.render([promise, lazy]);
1831+
const thirdPartyTransport = ReactNoopFlightServer.render(
1832+
[promiseComponent, lazy],
1833+
{
1834+
environmentName: 'third-party',
1835+
},
1836+
);
18321837

18331838
// Wait for the lazy component to initialize
18341839
await 0;
@@ -1840,16 +1845,20 @@ describe('ReactFlight', () => {
18401845
await act(async () => {
18411846
const promise = ReactNoopFlightClient.read(transport);
18421847
expect(promise._debugInfo).toEqual(
1843-
__DEV__ ? [{name: 'ServerComponent'}] : undefined,
1848+
__DEV__ ? [{name: 'ServerComponent', env: 'server'}] : undefined,
18441849
);
18451850
const result = await promise;
18461851
const thirdPartyChildren = await result.props.children[1];
18471852
// We expect the debug info to be transferred from the inner stream to the outer.
18481853
expect(thirdPartyChildren[0]._debugInfo).toEqual(
1849-
__DEV__ ? [{name: 'ThirdPartyComponent'}] : undefined,
1854+
__DEV__
1855+
? [{name: 'ThirdPartyComponent', env: 'third-party'}]
1856+
: undefined,
18501857
);
18511858
expect(thirdPartyChildren[1]._debugInfo).toEqual(
1852-
__DEV__ ? [{name: 'ThirdPartyLazyComponent'}] : undefined,
1859+
__DEV__
1860+
? [{name: 'ThirdPartyLazyComponent', env: 'third-party'}]
1861+
: undefined,
18531862
);
18541863
ReactNoop.render(result);
18551864
});

packages/react-noop-renderer/src/ReactNoopFlightServer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ const ReactNoopFlightServer = ReactFlightServer({
6868
});
6969

7070
type Options = {
71-
onError?: (error: mixed) => void,
71+
environmentName?: string,
7272
identifierPrefix?: string,
73+
onError?: (error: mixed) => void,
74+
onPostpone?: (reason: string) => void,
7375
};
7476

7577
function render(model: ReactClientValue, options?: Options): Destination {
@@ -80,6 +82,8 @@ function render(model: ReactClientValue, options?: Options): Destination {
8082
bundlerConfig,
8183
options ? options.onError : undefined,
8284
options ? options.identifierPrefix : undefined,
85+
options ? options.onPostpone : undefined,
86+
options ? options.environmentName : undefined,
8387
);
8488
ReactNoopFlightServer.startWork(request);
8589
ReactNoopFlightServer.startFlowing(request, destination);

packages/react-server-dom-esm/src/ReactFlightDOMServerNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function createDrainHandler(destination: Destination, request: Request) {
5252
}
5353

5454
type Options = {
55+
environmentName?: string,
5556
onError?: (error: mixed) => void,
5657
onPostpone?: (reason: string) => void,
5758
identifierPrefix?: string,
@@ -73,6 +74,7 @@ function renderToPipeableStream(
7374
options ? options.onError : undefined,
7475
options ? options.identifierPrefix : undefined,
7576
options ? options.onPostpone : undefined,
77+
options ? options.environmentName : undefined,
7678
);
7779
let hasStartedFlowing = false;
7880
startWork(request);

packages/react-server-dom-fb/src/ReactFlightDOMServerFB.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ function renderToDestination(
5050
model,
5151
null,
5252
options ? options.onError : undefined,
53+
undefined,
54+
undefined,
5355
);
5456
startWork(request);
5557
startFlowing(request, destination);

packages/react-server-dom-turbopack/src/ReactFlightDOMServerBrowser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export {
3434
} from './ReactFlightTurbopackReferences';
3535

3636
type Options = {
37+
environmentName?: string,
3738
identifierPrefix?: string,
3839
signal?: AbortSignal,
3940
onError?: (error: mixed) => void,
@@ -51,6 +52,7 @@ function renderToReadableStream(
5152
options ? options.onError : undefined,
5253
options ? options.identifierPrefix : undefined,
5354
options ? options.onPostpone : undefined,
55+
options ? options.environmentName : undefined,
5456
);
5557
if (options && options.signal) {
5658
const signal = options.signal;

packages/react-server-dom-turbopack/src/ReactFlightDOMServerEdge.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export {
3434
} from './ReactFlightTurbopackReferences';
3535

3636
type Options = {
37+
environmentName?: string,
3738
identifierPrefix?: string,
3839
signal?: AbortSignal,
3940
onError?: (error: mixed) => void,
@@ -51,6 +52,7 @@ function renderToReadableStream(
5152
options ? options.onError : undefined,
5253
options ? options.identifierPrefix : undefined,
5354
options ? options.onPostpone : undefined,
55+
options ? options.environmentName : undefined,
5456
);
5557
if (options && options.signal) {
5658
const signal = options.signal;

packages/react-server-dom-turbopack/src/ReactFlightDOMServerNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function createDrainHandler(destination: Destination, request: Request) {
4949
}
5050

5151
type Options = {
52+
environmentName?: string,
5253
onError?: (error: mixed) => void,
5354
onPostpone?: (reason: string) => void,
5455
identifierPrefix?: string,
@@ -70,6 +71,7 @@ function renderToPipeableStream(
7071
options ? options.onError : undefined,
7172
options ? options.identifierPrefix : undefined,
7273
options ? options.onPostpone : undefined,
74+
options ? options.environmentName : undefined,
7375
);
7476
let hasStartedFlowing = false;
7577
startWork(request);

packages/react-server-dom-webpack/src/ReactFlightDOMServerBrowser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export {
3838
} from './ReactFlightWebpackReferences';
3939

4040
type Options = {
41+
environmentName?: string,
4142
identifierPrefix?: string,
4243
signal?: AbortSignal,
4344
onError?: (error: mixed) => void,
@@ -55,6 +56,7 @@ function renderToReadableStream(
5556
options ? options.onError : undefined,
5657
options ? options.identifierPrefix : undefined,
5758
options ? options.onPostpone : undefined,
59+
options ? options.environmentName : undefined,
5860
);
5961
if (options && options.signal) {
6062
const signal = options.signal;

packages/react-server-dom-webpack/src/ReactFlightDOMServerEdge.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export {
3838
} from './ReactFlightWebpackReferences';
3939

4040
type Options = {
41+
environmentName?: string,
4142
identifierPrefix?: string,
4243
signal?: AbortSignal,
4344
onError?: (error: mixed) => void,
@@ -55,6 +56,7 @@ function renderToReadableStream(
5556
options ? options.onError : undefined,
5657
options ? options.identifierPrefix : undefined,
5758
options ? options.onPostpone : undefined,
59+
options ? options.environmentName : undefined,
5860
);
5961
if (options && options.signal) {
6062
const signal = options.signal;

0 commit comments

Comments
 (0)