-
-
Notifications
You must be signed in to change notification settings - Fork 85
Warning in Unmounted Component (react-router) #28
Comments
Can you provide a minimal example to reproduce? I'd love to get this error fixed for you if I can recreate it on my own environment. |
Sure! index.tsx:
package.json:
After some more investigation, I found that if you remove the setTimeout from the If you need my webpack config, I can provide that too (although I don't think it would be relevant, but you never know). |
I've encountered similar issues, I think there needs to be a way to remove all listeners when a component unmounts. |
All listeners are currently supposed to be removed on unmount. I will look
into this issue Sunday or Monday, as I am away for the next few days. :)
…On Thu, Dec 6, 2018, 11:52 AM Brian Quinn ***@***.*** wrote:
I've encountered similar issues, I think there needs to be a way to remove
all listeners when a component unmounts.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#28 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAU_HSHaPaWVIKgHcpwjIpuE5BtErjt0ks5u2XWYgaJpZM4ZCL0f>
.
|
@eeyang92 I have copied your code verbatim, but I am not getting an error. I used create-react-app to spin up an application. I deleted everything in
I had to change the ID from I didn't CRA with TypeScript by default, so I added these packages manually:
"This is the index page" flashes for a moment before I get "This the the login page" with a button. When I click the button, I'm presented with "This is the dashboard." @BDQ If you can provide a minimal reproduction of when you've encountered this in error, I'm willing to take a look at it as well. |
So I played around with it a bit more, and it looks like the warning only comes up when in a dev environment. (Specifically, Here is my example (cleaned up) as I have it on my system: https://github.com/eeyang92/reactn-dev-error-example |
@CharlesStover - I've dug into the code in global-state-manager.js and I think the issue might be around This issue occurs for me when I've got two components using to the same global key, it seems like |
EDIT: Both of these are reproducible. Example for BDQ's scenario: import * as React from 'react'
import * as ReactDOM from 'react-dom'
import { setGlobal, useGlobal } from 'reactn'
setGlobal({
value: false
});
const A = () => {
const [ value, setValue ] = useGlobal('value');
return value.toString();
};
const B = () => {
const [ value, setValue ] = useGlobal('value');
return value.toString();
};
export default function App() {
const [ value, setValue ] = useGlobal('value');
setTimeout(() => {
setValue(!value);
}, 250);
return (
<>
<A></A>
{value && <B></B>}
</>
);
}
ReactDOM.render(<App />, document.getElementById('app')) I'll get this fixed as soon as possible. |
Awesome! 😄 |
I've got what I believe is a fix for this situation. The problem is when a parent and child both listen to the same property, the parent re-rendering causes the child to unmount (in addition to itself unmounting) while the child is still queued to re-render. I've changed it so that unmounting a component also removes property listeners that are already queued to occur, and the error seems to have disappeared in the above examples. Let me know if you still encounter this issue. My commit will close this Issue, so feel free to make a new one. This will be released in a few moments as ReactN 0.1.8. |
@CharlesStover that fixed my issue, thanks for the fix! |
Hi there, I currently have a Login Component, and based on the server's response I will call (
react-router-dom
)<Redirect to='/dashboard' />
if the server responds with affirmation the user has a valid session cookie already. However, I get this warning inside my component:To clarify, the setState is already done by the time the redirect is called:
From the Warning, I get a hint that something should be cleaned up? Not sure if this is related to #5.
The text was updated successfully, but these errors were encountered: