-
Notifications
You must be signed in to change notification settings - Fork 48.5k
Re-rendering components into a document leaks components #423
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,23 @@ | |
|
||
"use strict"; | ||
|
||
var DOC_NODE_TYPE = 9; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already defined in the codebase. Maybe create a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've thought about this before but ended up letting us add a couple constants. I think we should only be accessing these in places where we know we're in a browser environment (since we're checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the time being, let's just keep this in like this and then followup to replace everything across the codebase separately. |
||
|
||
/** | ||
* @param {DOMElement} container DOM element that may contain a React component | ||
* @param {DOMElement|DOMDocument} container DOM element that may contain | ||
* a React component | ||
* @return {?*} DOM element that may have the reactRoot ID, or null. | ||
*/ | ||
function getReactRootElementInContainer(container) { | ||
return container && container.firstChild; | ||
if (!container) { | ||
return null; | ||
} | ||
|
||
if (container.nodeType === DOC_NODE_TYPE) { | ||
return container.documentElement; | ||
} else { | ||
return container.firstChild; | ||
} | ||
} | ||
|
||
module.exports = getReactRootElementInContainer; |
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.
Can you get rid of the
var container =
(lint is complaining about unused variables - not caught in this repo because we don't lint the tests)