-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Fix memory leak in ReactChildrenMutationWarningHook for SSR #7410
Conversation
and get element from `ReactComponentTreeHook` instead of keeping an internal store
Awesome job! Will there be a patch release for this fix? |
); | ||
}); | ||
|
||
it('should warn when children are mutated', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: not very clear why there are two tests, and how they are different (right not the name only differences is starting with "should")
This will probably go in 15.3.1. @franjohn21 Can you build from master and verify this fixes it? |
This looks right but I'd appreciate if you could verify this indeed fixes the leak. |
@keyanzhang @gaearon I can confirm I am seeing the memory leak removed with this change. Thanks for the quick turnaround time! |
I’m going to get this in because it’s better than status quo and I also need it for DEV perf regression I’m tackling right now. |
}, | ||
onComponentHasMounted(debugID) { | ||
handleElement(debugID, elements[debugID]); | ||
delete elements[debugID]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference: delete
is super slow on V8 with many items when using numeric keys. Even toString()
is not enough—you have to prepend them with something like .
* Remove onBeforeMountComponent hook event It is unnecessary. We now pass the element as part of onInstantiateComponent, and it can't change before mounting. * Remove onComponentHasMounted hook event It is unused after #7410. * Replace on(Begin|End)ReconcilerTimer hook events We already have onBeforeUpdateComponent. Let's just have on(Before?)(Mount|Update|Unmount)Component and stick with them. This removes double event dispatches in some hot spots. * Remove onComponentHasUpdated hook The tests still pass so presumably it was not necessary. * Add missing __DEV__ to TestUtils code * Replace on(InstantiateComponent|SetParent) with onBeforeMountComponent This lets us further consolidate hooks. The parent ID is now passed as an argument to onBeforeMountComponent() with the element. * Remove onMountRootComponent hook event It is unnecessary now that we pass the parent ID to onBeforeMountComponent. * Use parentDebugID = 0 both for roots and production This removes some awkward branching.
* corrected ReactChildrenMutationWarningHook's name * changed `onComponentHasMounted` to `onMountComponent` and get element from `ReactComponentTreeHook` instead of keeping an internal store (cherry picked from commit 5514ea3)
* Remove onBeforeMountComponent hook event It is unnecessary. We now pass the element as part of onInstantiateComponent, and it can't change before mounting. * Remove onComponentHasMounted hook event It is unused after #7410. * Replace on(Begin|End)ReconcilerTimer hook events We already have onBeforeUpdateComponent. Let's just have on(Before?)(Mount|Update|Unmount)Component and stick with them. This removes double event dispatches in some hot spots. * Remove onComponentHasUpdated hook The tests still pass so presumably it was not necessary. * Add missing __DEV__ to TestUtils code * Replace on(InstantiateComponent|SetParent) with onBeforeMountComponent This lets us further consolidate hooks. The parent ID is now passed as an argument to onBeforeMountComponent() with the element. * Remove onMountRootComponent hook event It is unnecessary now that we pass the parent ID to onBeforeMountComponent. * Use parentDebugID = 0 both for roots and production This removes some awkward branching. (cherry picked from commit 0e976e1)
Fixes #7406. Thanks @franjohn21 for providing such a detailed investigation!
Reviewers: @gaearon @jimfb