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] Track Current debugTask and run it for onError Callbacks #30182

Merged
merged 3 commits into from
Jul 2, 2024

Conversation

sebmarkbage
Copy link
Collaborator

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 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.

Screenshot 2024-07-01 at 10 52 29 PM

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

throwFiber._debugTask = debugInfo[i].task;

Then use them when invoking the error callbacks:

if (__DEV__) {
runWithFiberInDEV(errorInfo.source, logUncaughtError, root, errorInfo);
} else {
logUncaughtError(root, errorInfo);
}

Copy link

vercel bot commented Jul 2, 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 10:33pm
@react-sizebot
Copy link

react-sizebot commented Jul 2, 2024

Comparing: cfb8945...9b29577

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.41% 176.33 kB 178.81 kB +0.87% 31.87 kB 32.15 kB
oss-experimental/react-dom/cjs/react-dom-server.bun.development.js +0.73% 329.65 kB 332.06 kB +0.45% 63.73 kB 64.01 kB
oss-experimental/react-html/cjs/react-html.development.js +0.70% 342.85 kB 345.24 kB +0.44% 62.60 kB 62.87 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.node.development.js +0.64% 370.80 kB 373.19 kB +0.39% 66.80 kB 67.06 kB
oss-experimental/react-dom/cjs/react-dom-server-legacy.browser.development.js +0.64% 370.81 kB 373.19 kB +0.39% 66.80 kB 67.06 kB
oss-experimental/react-dom/cjs/react-dom-server.node.development.js +0.64% 389.06 kB 391.55 kB +0.43% 68.97 kB 69.27 kB
oss-experimental/react-dom/cjs/react-dom-server.browser.development.js +0.63% 393.59 kB 396.07 kB +0.42% 69.50 kB 69.79 kB
oss-experimental/react-dom/cjs/react-dom-server.edge.development.js +0.63% 394.14 kB 396.62 kB +0.40% 69.58 kB 69.86 kB
oss-experimental/react-html/cjs/react-html.react-server.development.js +0.49% 486.51 kB 488.89 kB +0.32% 88.13 kB 88.41 kB
oss-experimental/react-server/cjs/react-server.production.js +0.28% 116.38 kB 116.71 kB +0.13% 21.02 kB 21.04 kB
test_utils/ReactAllWarnings.js Deleted 62.88 kB 0.00 kB Deleted 15.69 kB 0.00 kB

Generated by 🚫 dangerJS against 9b29577

packages/react-server/src/ReactFizzServer.js Outdated Show resolved Hide resolved
Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
@sebmarkbage sebmarkbage merged commit 3db98c9 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 #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)
sebmarkbage added a commit that referenced this pull request Jul 4, 2024
…ing onError/onPostpone (#30206)

Stacked on #30197.

This is similar to #30182 and #21610 in Fizz.

Track the current owner/stack/task on the task. This tracks it for
attribution when serializing child properties.

This lets us provide the right owner and createTask when we
console.error from inside Flight itself. This also affects the way we
print those logs on the client since we need the owner and stack. Now
console.errors that originate on the server gets the right stack on the
client:

<img width="760" alt="Screenshot 2024-07-03 at 6 03 13 PM"
src="https://github.com/facebook/react/assets/63648/913300f8-f364-4e66-a19d-362e8d776c64">

Unfortunately, because we don't track the stack we never pop it so it'll
keep tracking for serializing sibling properties. We rely on "children"
typically being the last property in the common case anyway. However,
this can lead to wrong attribution in some cases where the invalid
property is a next property (without a wrapping element) and there's a
previous element that doesn't. E.g. `<ClientComponent title={<div />}
invalid={nonSerializable} />` would use the div as the attribution
instead of ClientComponent.

I also wrap all of our own console.error, onError and onPostpone in the
context of the parent component. It's annoying to have to remember to do
this though.

We could always wrap the whole rendering in such as context but it would
add more overhead since this rarely actually happens. It might make
sense to track the whole current task instead to lower the overhead.
That's what we do in Fizz. We'd still have to remember to restore the
debug task though. I realize now Fizz doesn't do that neither so the
debug task isn't wrapping the console.errors that Fizz itself logs.
There's something off about that Flight and Fizz implementations don't
perfectly align.
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
4 participants