Skip to content

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

Merged
merged 1 commit into from
Oct 29, 2013
Merged

Re-rendering components into a document leaks components #423

merged 1 commit into from
Oct 29, 2013

Conversation

andreypopp
Copy link
Contributor

This PR does three things:

  • provides test cases which
    • test if we are able to unmount a component mounted into a document.
    • test if we can get reference to a component mounted into a document.
  • fixes unmounting such components from document element
  • fixes if such components can be queried by its container element

Merge test cases only, make sure they are sane, make sure they fail without further commits, then merge the rest and see everything is green.


var getTestDocument;

var testDocument;

// TODO: Same as defined in ReactMount, should we export it from there?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there's a better way to test if we can get a reference to a component by a DOM node?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this function to its own module and require() it from ReactMount and here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wil introduce circular dependeny between new module and ReactMount. I think I can factor out getID, setID and purgeID functions into a separate module to mitigate that... what would be the best name for this module? ReactNodeCache?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a good idea. @benjamn ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's not so easy as I thought — too much coupling with ReactMount internals. Can we export getReactRootID for use in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean export via ReactMount.getReactRootID.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I didn't realize you were waiting on us!

About the separate module, I think we actually went in the opposite direction (I think we had a ReactID module) and coupled this more tightly to avoid some circular dependencies.

So for now go ahead and export that function.

@@ -18,12 +18,22 @@

"use strict";

var DOC_NODE_TYPE = 9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already defined in the codebase. Maybe create a DOMNodeTypes module and put that constant in there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Node.DOCUMENT_NODE for that or it's not standardised?

Copy link
Member

Choose a reason for hiding this comment

The 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 nodeType), but I wasn't sure at the time so didn't press the matter. Since then though we've added the constants in a couple other places and so long as it's supported in all browsers, we should probably just use Node.*. If anybody knows for sure or wants to test all browsers to make sure, chime up :)

Copy link
Member

Choose a reason for hiding this comment

The 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.

If we are to unmount a component mounted into a document element we should
unmount it from document.documentElement and not from document.firstChild which
is a doctype element in this specific case.
zpao added a commit that referenced this pull request Oct 29, 2013
Re-rendering components into a document leaks components
@zpao zpao merged commit 214e910 into facebook:master Oct 29, 2013
@zpao
Copy link
Member

zpao commented Oct 29, 2013

Awesome. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants