-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[Flight] Set Current Owner / Task When Calling console.error or invoking onError/onPostpone #30206
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
// This also gets sent to the client as the owner for the replaying log. | ||
const componentDebugInfo: ReactComponentInfo = { | ||
env: task.environmentName, | ||
owner: task.debugOwner, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd have the name of the component here too. That's why it shows up as <...>
in the console task. There's two reasons for this:
- We don't track the "type". In Fizz we track the parent on ComponentStackNode which has this info. We could potentially eagerly create componentDebugInfo for client components in case they error instead of lazily.
- We don't have a "name" of ClientReferences atm anyway which is why the error message itself has a
<...
.
ownerStack = ReactServer.captureOwnerStack | ||
? ReactServer.captureOwnerStack() | ||
: null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is for a more useful assertion failure when we run this test without the flag?
ownerStack = ReactServer.captureOwnerStack | |
? ReactServer.captureOwnerStack() | |
: null; | |
ownerStack = gate(flags => flags.enableOwnerStacks) | |
? ReactServer.captureOwnerStack() | |
: null; |
so that we don't miss this when cleaning up the flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just copy paste from another case but this test is a bit weird in that it's gated on DEV and not just ignored in DEV.
This tracks it for attribution when serializing child properties. 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. It also doesn't affect client errors - only attribution on the RSC server itself.
It's annoying to have to remember to do this. 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 although Fizz doesn't do that neither. Also wrap onError and onPostpone with this context.
We only clear these to avoid replaying logs from onError on the client. This doesn't make a difference because we're not clearing currentRequest for console.error but it should line up.
06948a6
to
e2e328c
Compare
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:
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.