-
Notifications
You must be signed in to change notification settings - Fork 115
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
Nested media queries cause state update on unmounted component #100
Comments
I'm sorry, can you elaborate. What is happening for you, what do you expect to happen? |
Just check the error in the console, when scaling down the window ;) Visually everything works as expected, but behind the screens React warns for changing state on an unmounted components. The child component tries to update when the media query becomes falsey, but it is already being unmounted by the parent components that implements the same media query. Normally this should be prevented by a proper componentWillUnmount logic, but I think there is some race condition. |
We're getting somewhere. It looks like it's Safari specific. Maybe browsers have different timing, when it comes to firing events. |
Ah I see. Yeah so we're already removing the event listener for media query changes in This doesn't really make sense. I'm running Linux myself, so it's kinda hard for me to reproduce this. I would really appreciate if you could get some more info on what happens in which exact order. |
Yeah, that's super weird. That would mean that for the child component it fires one cycle later than for the parent component. I'll see what I can do here, debugging-wise... |
The parent and the child have the same media query. When the media query gets triggered, the engine pushes two events to the event queue to be executed. The first event calls parent's
When we increase the width to more then 500px, we should only see |
@yiochen thanks for the write up, that makes a lot of sense. Soooo I guess this is a Safari bug? |
@yiochen Thanks indeed. I guess we can solve this easily, by making a thin wrapper around the addListener and removeListener that prevents this bug from happening. I'm happy to write a PR for this, if desired. |
PR's welcome :) |
@edorivai @Gersom-NL I come across this bug in my computer. The same code in https://codepen.io/gersomvg/pen/yxQgBB , I resize the Chrome several times, then it will show error info in Console. The screenshot is below My computer is Mac Pro, OS version is 10.14.6 (18G95), and Chrome version is 76.0.3809.87 (64 bit) |
The error can be reproduced when scaling down this codepen from above 720px to below 720px:
https://codepen.io/gersomvg/pen/yxQgBB
The text was updated successfully, but these errors were encountered: