From 938dfcb18b0c5f716b55c6a094ea638294e72d1d Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Sat, 4 Apr 2015 16:00:00 -0700 Subject: [PATCH] [POC] Better debugging stack traces 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? ![image](https://cloud.githubusercontent.com/assets/6820/6995020/aacf7f9e-dae2-11e4-9959-d4914cae5123.png) 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. --- examples/quadratic/example.js | 18 ++++++++++++++++++ src/browser/ui/React.js | 5 +++++ src/classic/element/ReactElement.js | 6 +++++- src/classic/element/ReactElementValidator.js | 6 ++++++ src/core/ReactReconciler.js | 16 +++++++++++++++- vendor/fbtransform/transforms/react.js | 13 ++++++++++++- 6 files changed, 61 insertions(+), 3 deletions(-) diff --git a/examples/quadratic/example.js b/examples/quadratic/example.js index 1be6a8a1cda..156427ae282 100644 --- a/examples/quadratic/example.js +++ b/examples/quadratic/example.js @@ -1,3 +1,20 @@ +var Foo = React.createClass({ + render: function() { + debugger; + return
{this.props.children}
; + } +}); + +var Z = React.createClass({ + render: function() { + return + a: {this.props.a}, + b: {this.props.b}, + c: {this.props.c} + ; + } +}); + var QuadraticCalculator = React.createClass({ getInitialState: function() { return { @@ -31,6 +48,7 @@ var QuadraticCalculator = React.createClass({ ax2 + bx + c = 0

Solve for x:

+