-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Pass error stack from call site to mutable warnings #6788
base: main
Are you sure you want to change the base?
Pass error stack from call site to mutable warnings #6788
Conversation
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.
Interesting changes - thanks for your PR and time! 🙌
function checkInvalidWriteDuringRender(stack?: string) { | ||
if (shouldWarnAboutAccessDuringRender()) { | ||
logger.warn( | ||
"Writing to `value` during component render. Please ensure that you don't access the `value` property nor use `set` method of a shared value while React is rendering a component.", | ||
{ strict: true } | ||
'!!Writing to `value` during component render. Please ensure that you do not access the `value` property or use `set` method of a shared value while React is rendering a component.', | ||
{ strict: true }, | ||
{ stack } |
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.
What do you think about moving Error().stack
inside the if condition to avoid unnecessary creation of Error()
instances and potential performance regressions?
- function checkInvalidWriteDuringRender(stack?: string) {
+ function checkInvalidWriteDuringRender() {
if (shouldWarnAboutAccessDuringRender()) {
logger.warn(
'!!Writing to `value` during component render. Please ensure that you do not access the `value` property or use `set` method of a shared value while React is rendering a component.',
{ strict: true },
- { stack }
+ { stack: Error().stack }
It would be ok for you?
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 change will add one more frame in the call stack, so I think that the Error object should be crated as close to the function exposed from reanimated (in this case - value
getter/setter) as possible.
I don't think that moving error object anywhere else is a valid solution, though. It will introduce more hassle and doesn't address the real problem. See my comment below explaining why.
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.
@piaskowyk from skimming hermes code I think the .stack
is a getter that will format a string so that would be slow. I think creating the Error() itself might be cheap and then I could only pass the error reference itself and access .stack
later.
Hey @louis-openspace! Thank you for your PR. The invalid read/write warning introduced in reanimated Even though your solution removes some unnecessary stack frames, it is not ideal, as it won't add much benefit to warnings and errors logged from other functions in reanimated, which are deeper in the call stack. It will always remove just these few logs related to the reanimated logger and keep all calls up to the point where the I think we should investigate the problem and find a valid solution for the new react native debugger instead of fixing the problem just in part in a way proposed in this PR. |
@MatiPl01 thanks, I'd be interested if you find a workaround with the RN debugger. This method of forwarding error stacks I got from |
I will look into recent changes in the react native logging system and will try to adapt logger in reanimated to be capable of displaying clean stack traces. I will let you know if I find something that works.
By saying that this approach is not ideal, I meant that you always have to create the Error object as close to the function called by the user as possible. So, let's say we have exported function It works fine in your case, as the |
Summary
Introduced in Reanimated 3.16, the "Writing/Reading to
value
during component render" warning is very difficult to debug because the error stack is created through several layers of log calls. By passing the error stack from the call site where the mutable is called, users can pinpoint the site where the mutable was invalidly read/write at the second stack trace line.Test plan