-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Unable to find node on an unmounted component #3562
Comments
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. |
Excuse me, you're throwing errors and then wondering why errors happen? ¯_(ツ)_/¯ I understand that you want to catch rejection with Suspense, but why you can't do this inside <React.Suspense fallback={<h1>Loading..</h1>}>
<FetchyChildren />
</React.Suspense> Actually, seems that related to facebook/react#14188 and should be fixed in next release by facebook/react#15312. |
I'm throwing a Promise, not an error, which is expected behaviour of React Suspense, and was wondering why Semantic is attempting to locate a node which has been unmounted. The way you've phrased your reply there carries some unnecessary snark.
I absolutely could do that, the reason I raised this report is because:
thank you for the links to the React issue tracker, it does appear that those tickets track the ultimate source of the issue. |
New APIs sometimes confusing me because errors outside Thank you for detailed responses and a repro case (!) ❤️
Can't agree there, but it can be caused because I know how it's implemented. |
Hi ! I'm new to react.js anf semantic-ui, and I think I get the same issue on Dropdown component. I use react-router, and each time I click on item, I get the same error: I tried several things, if I set my Dropdown components to not update |
Bug Report
This report demonstrates an issue in which a component which uses
<RefFindNode>
will cause a React tree crash becausefindDOMNode(this)
is called after a component has been unmounted.Steps
Here is a Code Sandbox which demonstrates the issue. You should open this in Firefox as Chrome will not display the precise error due to the error being cross-origin.
https://codesandbox.io/s/v8m974m98l
My understanding of the problem is that if a user unmounts a Semantic component that utilises
<RefFindNode />
after its initial mount, Semantic may attempt to access the DOM Node of that element after it is unmounted, causing a full app tree crash. A great way to demonstrate this is by usingReact.useEffect()
and throwing a Promise after initial render.In the sandbox above, you can see this by
throw
ing a Promise to simulate React Suspense from within a Semantic<Modal />
, for which the button is a trigger. The Promise is thrown after the first render due to the usage ofuseEffect()
anduseState()
.This can be taped over reinforced by enclosing the component which throws (
FetchyChildren
) inReact.Suspense
which prevents the thrownPromise
from propagating up the chain, such that the thrown Promise does not result in the Button being unmounted.This does appear to be specific to Promises: Throwing a generic error allows the error to propagate normally through to the usual lifecycles. It's only when throwing a Promise that I've seen so far that causes an app tree crash.
Expected Result
There should be no runtime error related to
findDOMNode()
or full app tree crash.Full expected behaviour is unclear, since in this case the
<Modal />
is the owner of its open/closed state and will get unmounted. I'd need someone more knowledgeable on the ins and outs of how Suspense works with its app tree to know the intended behaviour, but I'm pretty sure a full app tree crash is not it :)Actual Result
React App tree goes boom
Version
Semantic UI React 0.68.0
React 16.8.6
React DOM 16.8.6
Testcase
Apologies, I don't have time to fork your codesandbox right now because I have to go to a meeting, but I prepared a sandbox while trying to repro the bug from my own code and am happy to port it over though it should be reasonably understandable. Run the tests in Firefox because Chrome will not display the test error.
Unfortunately, it's not possible to use an assertion like
expect(() => act(() => button.click())).toThrow()
because there will be a weird error to do with code sandbox thrown.https://codesandbox.io/s/v8m974m98l
This is related to #3255, which states that wrapping your button with
forwardRef
will solve the issue - Unfortunately, the problem is within Semantic components and not userland ones. One way I have managed to patch over this is to indeed create a custom button component withforwardRef
, but Semantic'sButton
is still broken.The text was updated successfully, but these errors were encountered: