Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fizz] Implement debugInfo #30174

Merged
merged 2 commits into from
Jul 2, 2024
Merged

Conversation

sebmarkbage
Copy link
Collaborator

Stacked on #30170.

This lets us track Server Component parent stacks in Fizz which also lets us track the correct owner stack for lazy.

In Fiber we're careful not to make any DEV only fibers but since the ReactFizzComponentStack data structures just exist for debug meta data anyway we can just expand on that.

@sebmarkbage sebmarkbage requested review from gnoff and eps1lon July 1, 2024 18:18
Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 2, 2024 8:35pm
info += '\n' + owner.stack;
const ownerStack: string = owner.stack;
owner = owner.owner;
if (owner && ownerStack !== '') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For client components, we only included the stack if there was an owner (to eliminate some of the initial bootstrapping stacks) but we didn't do the same for server components. This fixes that in Fiber and Fizz.

@react-sizebot
Copy link

react-sizebot commented Jul 1, 2024

Comparing: 309e146...11fb115

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 497.99 kB 497.99 kB = 89.27 kB 89.27 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 502.81 kB 502.81 kB = 89.97 kB 89.97 kB
facebook-www/ReactDOM-prod.classic.js = 597.08 kB 597.08 kB = 105.33 kB 105.33 kB
facebook-www/ReactDOM-prod.modern.js = 571.42 kB 571.42 kB = 101.27 kB 101.27 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-server/cjs/react-server.development.js +1.12% 174.38 kB 176.33 kB +0.95% 31.57 kB 31.87 kB
oss-stable-rc/react-server/cjs/react-server.development.js +0.85% 158.65 kB 160.00 kB +0.87% 28.97 kB 29.22 kB
oss-stable-semver/react-server/cjs/react-server.development.js +0.85% 158.65 kB 160.00 kB +0.87% 28.97 kB 29.22 kB
oss-stable/react-server/cjs/react-server.development.js +0.85% 158.65 kB 160.00 kB +0.87% 28.97 kB 29.22 kB
oss-experimental/react-html/cjs/react-html.development.js +0.56% 340.94 kB 342.85 kB +0.46% 62.31 kB 62.60 kB
oss-experimental/react-dom/cjs/react-dom-server.bun.development.js +0.55% 327.85 kB 329.65 kB +0.45% 63.44 kB 63.72 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.node.development.js +0.53% 368.85 kB 370.80 kB +0.46% 66.49 kB 66.80 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.53% 368.85 kB 370.81 kB +0.46% 66.49 kB 66.80 kB
oss-experimental/react-dom/cjs/react-dom-server.node.development.js +0.50% 387.11 kB 389.06 kB +0.42% 68.68 kB 68.97 kB
oss-experimental/react-dom/cjs/react-dom-server.browser.development.js +0.50% 391.64 kB 393.59 kB +0.46% 69.18 kB 69.50 kB
oss-experimental/react-dom/cjs/react-dom-server.edge.development.js +0.50% 392.18 kB 394.14 kB +0.45% 69.27 kB 69.58 kB
oss-experimental/react-html/cjs/react-html.react-server.development.js +0.39% 484.60 kB 486.51 kB +0.34% 87.84 kB 88.13 kB
oss-stable-rc/react-dom/cjs/react-dom-server-legacy.node.development.js +0.39% 344.82 kB 346.16 kB +0.40% 63.14 kB 63.39 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.node.development.js +0.39% 344.82 kB 346.16 kB +0.40% 63.14 kB 63.39 kB
oss-stable-rc/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.39% 344.83 kB 346.17 kB +0.40% 63.13 kB 63.39 kB
oss-stable-semver/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.39% 344.83 kB 346.17 kB +0.40% 63.13 kB 63.39 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.node.development.js +0.39% 344.85 kB 346.19 kB +0.40% 63.16 kB 63.41 kB
oss-stable/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.39% 344.85 kB 346.19 kB +0.40% 63.16 kB 63.41 kB
facebook-www/ReactDOMServerStreaming-dev.modern.js +0.38% 349.20 kB 350.54 kB +0.38% 63.49 kB 63.73 kB
oss-stable-rc/react-dom/cjs/react-dom-server.node.development.js +0.38% 352.09 kB 353.43 kB +0.40% 63.72 kB 63.98 kB
oss-stable-semver/react-dom/cjs/react-dom-server.node.development.js +0.38% 352.09 kB 353.43 kB +0.40% 63.72 kB 63.98 kB
oss-stable/react-dom/cjs/react-dom-server.node.development.js +0.38% 352.16 kB 353.50 kB +0.40% 63.75 kB 64.01 kB
facebook-www/ReactDOMServer-dev.modern.js +0.38% 356.62 kB 357.96 kB +0.37% 64.69 kB 64.93 kB
oss-stable-rc/react-dom/cjs/react-dom-server.browser.development.js +0.38% 356.95 kB 358.29 kB +0.38% 65.06 kB 65.30 kB
oss-stable-semver/react-dom/cjs/react-dom-server.browser.development.js +0.38% 356.95 kB 358.29 kB +0.38% 65.06 kB 65.30 kB
oss-stable/react-dom/cjs/react-dom-server.browser.development.js +0.38% 357.02 kB 358.36 kB +0.38% 65.08 kB 65.33 kB
oss-stable-rc/react-dom/cjs/react-dom-server.edge.development.js +0.38% 357.50 kB 358.84 kB +0.38% 65.16 kB 65.41 kB
oss-stable-semver/react-dom/cjs/react-dom-server.edge.development.js +0.38% 357.50 kB 358.84 kB +0.38% 65.16 kB 65.41 kB
oss-stable/react-dom/cjs/react-dom-server.edge.development.js +0.38% 357.57 kB 358.91 kB +0.38% 65.19 kB 65.43 kB
facebook-www/ReactDOMServer-dev.classic.js +0.37% 359.22 kB 360.55 kB +0.38% 65.14 kB 65.39 kB
oss-stable-rc/react-dom/cjs/react-dom-server.bun.development.js +0.35% 305.93 kB 307.01 kB +0.34% 60.11 kB 60.32 kB
oss-stable-semver/react-dom/cjs/react-dom-server.bun.development.js +0.35% 305.93 kB 307.01 kB +0.34% 60.11 kB 60.32 kB
oss-stable/react-dom/cjs/react-dom-server.bun.development.js +0.35% 306.00 kB 307.07 kB +0.33% 60.14 kB 60.34 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Generated by 🚫 dangerJS against 11fb115

);
expect(normalizeCodeLocInfo(caughtErrors[0].ownerStack)).toBe(
__DEV__ && gate(flags => flags.enableOwnerStacks)
? '\n in Bar (at **)' + '\n in Foo (at **)'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the actual paths here point to fake evals which needs to be source mapped to make sense since this is the "client" stacks showing.

An alternative would be to snapshot the stacks on the "server" and then show it here. However, the server likely is compiled and needs to be source mapped anyway so might not matter much.

expect(caughtErrors[0].error).toBe(thrownError);
expect(normalizeCodeLocInfo(caughtErrors[0].parentStack)).toBe(
__DEV__
? '\n in Baz (at **)' +
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't have line numbers because they're server components and we don't give those line numbers for parent stacks.

}
return node;
}
// eslint-disable-next-line react-internal/prod-error-codes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reason here that this error shouldn't appear in prod bundles? We usually call this out explicitly e.g.

// These errors should never make it into a build so we don't need to encode them in codes.json
// eslint-disable-next-line react-internal/prod-error-codes
throw new Error(
'emitConsoleChunk should never be called in production mode. This is a bug in React.',
);

Copy link
Collaborator Author

@sebmarkbage sebmarkbage Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the caller should always be wrapped in a __DEV__ check. We don't always comment and the comments that we do have don't really say anything more than what the disable line says anyway so it's a classic unnecessary commment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

say anything more than what the disable line says anyway so it's a classic unnecessary commment.

To me the eslint-disable doesn't say anything. I think it's only useless if you have high context.

This lets us track Server Component parent stacks in Fizz which also lets
us track the correct owner stack for lazy.

In Fiber we're careful not to make any DEV only fibers but since the
ReactFizzComponentStack data structures just exist for debug meta data
anyway we can just expand on that.
@sebmarkbage sebmarkbage merged commit cfb8945 into facebook:main Jul 2, 2024
139 checks passed
github-actions bot pushed a commit that referenced this pull request Jul 2, 2024
Stacked on #30170.

This lets us track Server Component parent stacks in Fizz which also
lets us track the correct owner stack for lazy.

In Fiber we're careful not to make any DEV only fibers but since the
ReactFizzComponentStack data structures just exist for debug meta data
anyway we can just expand on that.

DiffTrain build for [cfb8945](cfb8945)
sebmarkbage added a commit that referenced this pull request Jul 2, 2024
Stacked on #30174.

This tracks the current debugTask on the Task so that when an error is
thrown we can use it to run the `onError` (and `onShellError` and
`onFatalError`) callbacks within the Context of that task. Ideally it
would be associated with the error object but neither console.error [nor
reportError](https://crbug.com/350426235) reports this as the async
stack so we have to manually restore it.

That way when you inspect Fizz using node `--inspect` we show the right
async stack.

<img width="616" alt="Screenshot 2024-07-01 at 10 52 29 PM"
src="https://github.com/facebook/react/assets/63648/db68133e-124e-4509-8241-c67160db94fc">

This is equivalent to how we track the task that created the parent
server component or the Fiber:


https://github.com/facebook/react/blob/6d2a97a7113dfac2ad45067001b7e49a98718324/packages/react-reconciler/src/ReactChildFiber.js#L1985

Then use them when invoking the error callbacks:


https://github.com/facebook/react/blob/6d2a97a7113dfac2ad45067001b7e49a98718324/packages/react-reconciler/src/ReactFiberThrow.js#L104-L108

---------

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
github-actions bot pushed a commit that referenced this pull request Jul 2, 2024
Stacked on #30174.

This tracks the current debugTask on the Task so that when an error is
thrown we can use it to run the `onError` (and `onShellError` and
`onFatalError`) callbacks within the Context of that task. Ideally it
would be associated with the error object but neither console.error [nor
reportError](https://crbug.com/350426235) reports this as the async
stack so we have to manually restore it.

That way when you inspect Fizz using node `--inspect` we show the right
async stack.

<img width="616" alt="Screenshot 2024-07-01 at 10 52 29 PM"
src="https://github.com/facebook/react/assets/63648/db68133e-124e-4509-8241-c67160db94fc">

This is equivalent to how we track the task that created the parent
server component or the Fiber:

https://github.com/facebook/react/blob/6d2a97a7113dfac2ad45067001b7e49a98718324/packages/react-reconciler/src/ReactChildFiber.js#L1985

Then use them when invoking the error callbacks:

https://github.com/facebook/react/blob/6d2a97a7113dfac2ad45067001b7e49a98718324/packages/react-reconciler/src/ReactFiberThrow.js#L104-L108

---------

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>

DiffTrain build for [3db98c9](3db98c9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
5 participants