Skip to content
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

ReactTestUtils.renderIntoDocument() resources clean up and documentation #10330

Closed
the-spyke opened this issue Jul 31, 2017 · 2 comments
Closed

Comments

@the-spyke
Copy link

Do you want to request a feature or report a bug?

Feature/documentation

What is the current behavior?

There is almost none documentation about how to actually use .renderIntoDocument() method. I can't find find answers on those questions on Jest's website or enzyme's (I know that it's not Facebook) either.

  • If I render a component into a DOM in a test, how will it be destroyed?
  • Should I clean up by myself?
  • What tools to use for this?
  • Just .unmountComponentAtNode()?
  • Where I will get the container to pass in?
  • What about additional component trees like in Popovers?
  • What are the best ways to test that there aren't any parts left after my component were unmounted?

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/84v837e9/).

What is the expected behavior?

It will be nice to see such information before people will met memory leaks in their tests, and also help to establish good practices for writing tests.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

@the-spyke the-spyke changed the title .renderIntoDocument() clean up and documentation renderIntoDocument resources clean up and documentation Aug 3, 2017
@the-spyke the-spyke changed the title renderIntoDocument resources clean up and documentation ReactTestUtils.renderIntoDocument() resources clean up and documentation Aug 3, 2017
@the-spyke
Copy link
Author

Answering my own questions:

  • Calling .renderIntoDocument() returns you an instance
  • This instance was rendered into freshly created DOM element, which now represents a detached tree
  • There's also a reference to the instance in ReactDOM's internal map
  • So, even if you remove all your references to this instance, on every call to .renderIntoDocument() you will get 1 detached tree hanging in memory + 1 instance of a React component with all its props not available for garbage collection

@bvaughn
Copy link
Contributor

bvaughn commented Oct 6, 2017

Thank you for filing this issue! 😄

The documentation and source code for reactjs.org now lives in a different repository: reactjs/reactjs.org. (For more info on why we made this move, see issue #11075.)

I've moved your issue to the new repo: reactjs/react.dev#28

Let's continue the discussion there! Sorry for the inconvenience.

@bvaughn bvaughn closed this as completed Oct 6, 2017
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

No branches or pull requests

3 participants