You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
ReactMount.nodeCache is repopulated with purged nodes that are focused at unmount #2988
If you unmount a currently focused node, nodeCache is repopulated after being purged and unless that specific ID is revisited later, it will remain there forever. This is mostly likely due to the focus/selection restoration phase after reconciliation.
I'll go ahead and put good first bug on this one, it may be a bit tricky to find the root cause but it should be quite easy to narrow down and the fix should be rather simple too I think. So perhaps not the easiest bug if you're entirely new.
@javpaw I can have it fixed in an hour or so, but really, just change var nodeCache = {} to var nodeCache = window.nodeCache = {} and run that code against your own React build and you'll see it.
After a bunch of experimentation related to the fix in #3144, I was able to trace this issue to EventListener, and specifically to the fact that event the default event handlers (added as part of ReactBrowserEventEmitter.listenTo) aren't removed when unmounting.
It looks like when an <input> is mounted, it attaches listeners for focus, blur, etc.
So a remove function is being returned, it's just not getting used. I think if we exposed remove as callable (and called it before the component is removed from the DOM), we'd be in the clear.
I'm not sure where best to handle this, given that I'm fairly new to React's source and it's sort of massive. Are there any conventions in use or places that I should look?
Right right, but it seems like there's a handler getting attched that's firing the blur event that causes the node to get recached when it's unmounted (or at least, that's what the stack points to when I climb through it) -- the browser's native handling of removing an input component is triggering this handler.
Yes; the fix is probably to change React's event handling to not fire events on removed nodes. (If another root is still mounted, we can't remove the top-level handler anyway.) cc #3298, #3790
@spicyj I think we intentionally fire events on removed nodes. I'm pretty sure there was a unit test for that, ensuring that we fire an event on nodes even if they are removed as part of an event handler as the event bubbles up.
Spec says it should not get confused by disappearing elements, which I suppose is sufficiently vague as to imply any non-fatal but still undefined behavior :).
Activity
syranide commentedon Jan 31, 2015
I'll go ahead and put good first bug on this one, it may be a bit tricky to find the root cause but it should be quite easy to narrow down and the fix should be rather simple too I think. So perhaps not the easiest bug if you're entirely new.
javpaw commentedon Feb 4, 2015
Hi syranide, I'd like to take a look but the link is not working, can you check it please?
syranide commentedon Feb 4, 2015
@javpaw I can have it fixed in an hour or so, but really, just change
var nodeCache = {}tovar nodeCache = window.nodeCache = {}and run that code against your own React build and you'll see it.syranide commentedon Feb 4, 2015
Fixed.
pletcher commentedon Jun 22, 2015
After a bunch of experimentation related to the fix in #3144, I was able to trace this issue to
EventListener, and specifically to the fact that event the default event handlers (added as part ofReactBrowserEventEmitter.listenTo) aren't removed when unmounting.It looks like when an
<input>is mounted, it attaches listeners forfocus,blur, etc.https://github.com/facebook/react/blob/master/src/renderers/dom/client/ReactBrowserEventEmitter.js#L271-L275
Which leads us to https://github.com/facebook/react/blob/master/src/renderers/dom/client/ReactEventListener.js#L145-L155
and finally to https://github.com/facebook/react/blob/master/src/shared/vendor/stubs/EventListener.js#L74-L79
So a
removefunction is being returned, it's just not getting used. I think if we exposedremoveas callable (and called it before the component is removed from the DOM), we'd be in the clear.I'm not sure where best to handle this, given that I'm fairly new to React's source and it's sort of massive. Are there any conventions in use or places that I should look?
sophiebits commentedon Jun 22, 2015
@pletcher You're right that those aren't removed, but they're added only once per document at the top level so that shouldn't really be a problem.
pletcher commentedon Jun 22, 2015
Right right, but it seems like there's a handler getting attched that's firing the
blurevent that causes the node to get recached when it's unmounted (or at least, that's what the stack points to when I climb through it) -- the browser's native handling of removing aninputcomponent is triggering this handler.sophiebits commentedon Jun 22, 2015
Yes; the fix is probably to change React's event handling to not fire events on removed nodes. (If another root is still mounted, we can't remove the top-level handler anyway.) cc #3298, #3790
jimfb commentedon Jun 23, 2015
@spicyj I think we intentionally fire events on removed nodes. I'm pretty sure there was a unit test for that, ensuring that we fire an event on nodes even if they are removed as part of an event handler as the event bubbles up.
jimfb commentedon Jun 23, 2015
Yeah, https://github.com/facebook/react/blob/master/src/renderers/dom/client/__tests__/ReactEventListener-test.js#L93
Spec says
it should not get confused by disappearing elements, which I suppose is sufficiently vague as to imply any non-fatal but still undefined behavior :).sophiebits commentedon Jun 23, 2015
Yeah, goes back to #1105.
nhunzaker commentedon Apr 2, 2016
Looks like nodeCache was killed in 4ba0e95. Is this still an issue?
sophiebits commentedon Apr 2, 2016
Nope, thank you.