Skip to content

Commit

Permalink
[Fiber] Transfer _debugInfo from Arrays, Lazy, Thenables and Elemen…
Browse files Browse the repository at this point in the history
…ts to the inner Fibers. (facebook#28286)

That way we can use it for debug information like component stacks and
DevTools. I used an extra stack argument in Child Fiber to track this as
it's flowing down since it's not just elements where we have this info
readily available but parent arrays and lazy can merge this into the
Fiber too. It's not great that this is a dev-only argument and I could
track it globally but seems more likely to make mistakes.

It is possible for the same debug info to appear for multiple child
fibers like when it's attached to a fragment or a lazy that resolves to
a fragment at the root. The object identity could be used in these
scenarios to infer if that's really one server component that's a parent
of all children or if each child has a server component with the same
name.

This is effectively a public API because you can use it to stash
information on Promises from a third-party service - not just Server
Components. I started outline the types for this for some things I was
planning to add but it's not final.

I was also planning on storing it from `use(thenable)` for when you
suspend on a Promise. However, I realized that there's no Hook instance
for those to stash it on. So it might need a separate data structure to
stash the previous pass over of `use()` that resets each render.

No tests yet since I didn't want to test internals but it'll be covered
once we have debugging features like component stacks.
  • Loading branch information
sebmarkbage authored and AndyPengc12 committed Apr 15, 2024
1 parent d96c091 commit ffc250e
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 29 deletions.
12 changes: 7 additions & 5 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
* @flow
*/

import type {Thenable} from 'shared/ReactTypes';
import type {
Thenable,
ReactDebugInfo,
ReactComponentInfo,
ReactAsyncInfo,
} from 'shared/ReactTypes';
import type {LazyComponent} from 'react/src/ReactLazy';

import type {
Expand Down Expand Up @@ -76,9 +81,6 @@ const RESOLVED_MODULE = 'resolved_module';
const INITIALIZED = 'fulfilled';
const ERRORED = 'rejected';

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

type PendingChunk<T> = {
status: 'pending',
value: null | Array<(T) => mixed>,
Expand Down Expand Up @@ -1014,7 +1016,7 @@ function resolveHint<Code: HintCode>(
function resolveDebugInfo(
response: Response,
id: number,
debugInfo: {name: string},
debugInfo: ReactComponentInfo | ReactAsyncInfo,
): void {
if (!__DEV__) {
// These errors should never make it into a build so we don't need to encode them in codes.json
Expand Down
Loading

0 comments on commit ffc250e

Please sign in to comment.