-
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
Media tries to update unmounted component #139
Comments
Thanks for the report. It would be really helpful if you could create a reproducible Codesandbox.
|
Here is a little codepen: https://codepen.io/jonask94/pen/jOOveEJ |
Thanks, I'll have to look into this. |
Issue ReactTraining#139 was the same issue I was having when resizing a window. I was receiving an error about a possible memory leak since setState was called on an unmounted component. It seems like the `getMatches` call was taking just long enough that the component could be unmounted while it was executing. By using a `_mounted` flag, we can determine if it is safe to call `setState` and bypass it if the component is unmounted. I looked at using an abort signal, but I don't think the `matchMedia` API is robust enough for that currently.
I suspected that the issue lay in the listener being created in the constructor, and playing havoc with the `this` scope so I broke it out into its own function and passed the necessary parameters in. This succeeded in resolving the issue reported in ReactTraining#139 by removing the root of the issue instead of covering it up with my previous PR.
I have the same issue.
If I navigate to the page with the Media component and navigate away to another page then change the view to say mobile or table (in browser inspect), I get the error above. |
I got this warning in my app using "react-media" 1.10.0. App uses React 16.9.
I'm not sure what I did before the warning fired. Sorry :/ |
I'm getting this bug as well working with NextJS. You can reproduce it easily with a default installation of NextJS. |
Also getting this error:
I'm not using state at my component, so I think I can ignore this error. |
I think the root cause is the method In I'd like to fix it but I saw that someone has a PR to refactor the whole component to the functional component, and in that PR he use the Let's wait for his PR to be merged. |
PR has been merged, it's available at |
I can't repro it with the version |
Hey one thing needs to be pointed out. This issue will happen again if you are in the development mode using the I don't think it is a blocking issue since it only happens in the dev env, let's keep investigation. |
The error still present when using |
The error still persists, I have version 1.10.0 installed and I still get. The PR already approved? When would this problem be solved? index.js:1 Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to "react": "^16.13.1", |
@jhimelymendoza can you try |
@edorivai I'm seeing the same issue using |
Same here |
@jonkan @clieee @jhimelymendoza could you guys confirm whether you're seeing this with Would also be helpful if y'all could post browser and react-media versions. 🙏 |
@edorivai I'm seeing it with |
I'm seeing it with |
Hello, I've gotten error in Chrome 103.0: "react_devtools_backend.js:4026 Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to I don't use state in this component |
I'm also experiencing the error on Chrome. "Warning: Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to This is in |
The issue still persists. |
I’m getting the following warning from a Media-Component which implements a min-width media query:
„Can't perform a React state update on an unmounted component“.
The warning is thrown when the component is already unmounted and the user resizes the window.
It seems as if the event-listener which updates the matches-state is still alive after unmounting.
When inspecting the code I wondered why the initialize-function of Media.js is called two times (1. in constructor, 2. in componentDidMount). Doesn’t this behaviour ends up in eventListeners that will never be removed since in componentWillUnmount only the listeners created in the second call of initialize will be eleminiated?
I’m currently using react-media in version 1.10.0
The text was updated successfully, but these errors were encountered: