-
Notifications
You must be signed in to change notification settings - Fork 70
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
Extending the console to improve developer experience #163
Comments
Related "tag stack" issues: |
I don't want to get tangled in implementation strategies too early, but it seems worth mentioning some additional concerns related to a stack-capturing approach like mentioned in the above issues.
For example, React apps often update in response to user input (keyboard event or click event). The event handler schedules an update with React and React later1 decides which components in the tree need to be re-rendered, etc. If an error is logged somewhere deep in the tree during such an update, there are two unfortunate things currently:
Ideally we could construct a call stack that includes at least the full component stack if not also the source of the update2. If we needed to re-use captured stacks from previous renders though, the frames above a given React component would probably not be relevant- since they would correspond to the code path that previously rendered a given component, rather than e.g. the click handler that scheduled the update. 1 I say "later" because there is often at least one tick between these two events, maybe longer. |
Can you provide some code for this? I'm having trouble visualizing exactly whats going on. |
Here's a Code Sandbox: https://codesandbox.io/s/silly-agnesi-07ro8 The console log demonstrates that the initial "mount" renders the Here's the warning stack that's logged during mount: If you click on the "unknown" button, here's the warning stack that will be logged: Couple of things this illustrates:
Regarding my note about "later" above- if I were to use the concurrent rendering mode, the update stack would also not include the event dispatch either: |
Rather than create an entirely new For what it's worth, Web Inspector tries to detect when a logged string looks like a stack trace, and presents it as such in the UI. |
I'm not sure how setting a display property on |
@bvaughn |
This is just an example. There are lots of things that are warnings in this category (e.g. "Foo has been deprecated and will be removed in the upcoming release") In either case, there is no actual |
Let me note a connection to https://github.com/tc39/proposal-function-implementation-hiding which myself and @michaelficarra are working on. See especially tc39/proposal-function-implementation-hiding#23 which summarizes some of the latest discussion. One thing to keep in mind is that the console's stack trace is different from
In summary I don't think proposal-function-implementation-hiding is going to help that much, so it is best to continue pursuing this as part of the console work. But I wanted to make a note. Finally I'll also note that the non-standard |
Thanks for the pointer @domenic! That could be useful for the console override approach this issue outlines, making it less observable. Agreed it wouldn't be sufficient for this proposal on its own though 😄 |
General goal makes sense to me. But I'm uncertain how standardization would work, considering that Error.stack nor console outputis standardized. |
Is there going to be a way to print out the component stack in node env? DevTools are great but it doesn't help much when the app is SSRed and dead before even hitting the browser. I was really excited about the original |
@tajo Discussion about React-specific APIs should probably happen in the React repo 😄 An abstract concept of something like React's component stacks is relevant to this issue, but an API that exposed component stacks to application code wouldn't really be. |
Ah oops, I didn't realize this is not a React repo. |
FWIW relevance and importance of this issue is coming up again due to a recent change on the React side: facebook/react#22257 (comment) @domenic It doesn't look like there's been any movement on the tc39 proposal you linked to. Any other relevant proposals my team could throw our support behind? (Or anything else you'd suggest us doing?) |
This issue is meant as a conversation starter around tools like React DevTools. The following GitHub issues provide some additional background context:
This issue relates to both logging and call stacks. I'll try to keep this issue mostly focused on the logging/console aspect but there will be some overlap.
Summary
At a high level, it would be nice if there were a way for frameworks or extensions to extend console methods (like
console.error
) without exposing themselves in the stack that the browser captures.I'll use React and the React DevTools as an example. We recently added a feature to auto-append some additional info- referred to as "component stack" (explained below) to error logs. We do this because the call stack alone is often insufficient to identify the cause of an error. Conceptually, I think this is similar to the async call stack feature in terms of how it helps developers identify problems and debug their code.
The only mechanism we currently have to append this information is to override the built-in console method, e.g.
Unfortunately this means our override method is the top stack frame, so it's observable along with the error being logged:
It would be nice if there were a way for us to tell the console to ignore, or skip over, the top most frame (our override method) like it does with its own internal methods.
It would also be nice if the appended "component stack" were an actual, clickable stack rather than just an appended string of text.
Althoguh the above example shows
console.error
being called from within a component (in user code). In many cases, React itself might log what logs the error, even though it's about a component.In this example, the relevant user code (React component) isn't even in the call stack anywhere, only in the appended "component stack". It would also be nice if there were a way for us to add it.
What are "component stacks"?
React applications are trees of components. These trees are built at runtime by "rendering" each component.
Here's an example app:
The above code can be thought of as a tree:
Some things of note about this tree:
With recursive code, this sort of thing more or less "just works". However because of React's concurrent rendering mode, it processes the tree iteratively. This means that at the time our example error is logged, the JavaScript callstack doesn't provide enough information to identify where the source of the problem is:
The above call stack mostly consists of React internals. While it's helpful and meaningful to those of us working on React, it isn't all that helpful to most application developers when it comes to finding the source of their problem.
The text was updated successfully, but these errors were encountered: