-
Notifications
You must be signed in to change notification settings - Fork 48.8k
[POC] Better debugging stack traces #3586
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
Conversation
I had an idea: what if our stack traces looked more like this so you don't just have 30 frames inside React and then a top-level render call, which is the typical situation nowadays?  Turns out we can do this with a small hack. Each time we create an element, we store away a function that just calls its argument: ```js var foo = React.createElementDebug(function element_Foo(x) { x(); }, Foo, ...); ``` then when we go to mount the component, we call this function with the mount code as argument so that it appears on the stack. This is a little crazy and probably slow, but could make development nicer. You can't inspect the props (e.g., `a`, `b`, `c` here) but if we had the function capture those vars I think you could.
This is actually a really neat insight! Another thing we were considering was using Promises so that the async debugging tools in Chrome would work. Lets keep iterating on something like this. |
@spicyj Here's a kind of related thought: If you have a properly inferred name on the render function. E.g. ES6 classes would have a name like "MyComponent.render". What if we in You could even use this to infer the "owner" name for use by debug outputs. That could allow us to avoid tracking owner even in debug mode. |
Yes, we could. I assumed that would be much slower than this and not much more useful. |
The benefits are that A) it works with unchanged syntax and any caller, not just JSX. B) it shows indirections. The downside is that you don't get the breakpoint debugger which is really neat. |
cc @jaredly |
This is interesting but I’m not sure how feasible this would be perf-wise, or whether it would actually improve the situation rather than introduce more confusion. Deep and seemingly unrelated stack traces are a real problem so let’s continue tracking it in #5460. I will close this PR, but we can revisit it later. |
Yeah I remember we had lots of discussions about this last year, but didn't come up with anything sufficiently performant. |
I had an idea: what if our stack traces looked more like this so you don't just have 30 frames inside React and then a top-level render call, which is the typical situation nowadays?
Turns out we can do this with a small hack. Each time we create an element, we store away a function that just calls its argument:
then when we go to mount the component, we call this function with the mount code as argument so that it appears on the stack.
This is a little crazy and probably slow, but could make development nicer. You can't inspect the props (e.g.,
a
,b
,c
here) but if we had the function capture those vars I think you could.