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

Show react stack trace on warnings #301

Open
chasestarr opened this issue Mar 22, 2019 · 3 comments
Open

Show react stack trace on warnings #301

chasestarr opened this issue Mar 22, 2019 · 3 comments

Comments

@chasestarr
Copy link
Contributor

Thought of this in response to new React.warn() and React.error() utilities. Was concerned about warnings from mixing long/short hand property names since it comes up often, but could possibly apply to others.

Trouble is that console.warn is called from the atomic-engine rather than the react package. Unsure exactly how the warn call could be 'caught' in the react code, but maybe there is another approach I'm not thinking of.

contrived example: https://codesandbox.io/s/9y8j4jkkw with error message below has no stack trace information. Imagine if working in a larger codebase, or customizing a dependency that uses styletron.

Styles `{"margin":"20px"}` and `{"marginTop":"10px"}` in object yielding class "ae af ag"
may result in unexpected behavior. Mixing shorthand and longhand properties within the
same style object is unsupported with atomic rendering. 
@rtsao
Copy link
Member

rtsao commented Mar 23, 2019

Yeah I was thinking about this; I think we can add some way to have context passed from the react package to the engine and/or vice-versa.

The simplest thing I can think of would be adding an additional argument to each engine method call.

const ctx = {
  warn: msg => React.warn(msg),
  error: msg => React.error(msg),
};

engine.injectStyle(style, ctx);

Alternatively, this could be a callback.

@rtsao
Copy link
Member

rtsao commented Sep 10, 2019

Alternatively, styletron-react could use try/catch and re-throw errors after calling React.error. But this can't be used for warnings, so making this part of the styletron-engine-atomic API might be better.

@rtsao
Copy link
Member

rtsao commented Sep 10, 2019

React.warn and React.error was reverted and never released, but we can still get access to the stack via

React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactDebugCurrentFrame.getStackAddendum()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants