8000 Another fix for #4876, TransitionGroup errors by jrowny · Pull Request #6710 · facebook/react · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Another fix for #4876, TransitionGroup errors #6710

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

Closed
wants to merge 1 commit into from

Conversation

jrowny
Copy link
@jrowny jrowny commented May 5, 2016

If the component has unmounted before a transition completes, sometimes the ref is undefined therefore it will throw. By adding a check to make sure we actually successfully got the ref, we avoid the error.

This is a fix for 4876

If the component has unmounted before a transition completes, sometimes the ref is undefined therefore it will throw. By adding a check to make sure we actually successfully got the ref, we avoid the error.
@ghost
Copy link
ghost commented May 5, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

8000

@jrowny
Copy link
Author
jrowny commented May 5, 2016

CLA signed.

@ghost
Copy link
ghost commented May 5, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@ghost ghost added the CLA Signed label May 5, 2016
@jimfb
Copy link
Contributor
jimfb commented May 6, 2016

I wonder if this is a duplicate of #6538, which has already been fixed in master using a different solution.

Can you create a unit test that fails without this change and passes with this change? We should have that as a regression test anyway, assuming this bug is not already fixed in master.

@jrowny
Copy link
Author
jrowny commented May 9, 2016

I don't think it's related as this is specifically for ReactTransitionGroup, but I can create a test case as it's pretty easy to repro.

@jimfb
Copy link
Contributor
jimfb commented May 11, 2016

Perhaps this is a fix for #5296

@gaearon
Copy link
Collaborator
gaearon commented May 11, 2016

I can create a test case as it's pretty easy to repro.

This would be most helpful!

@jrowny
Copy link
Author
jrowny commented May 11, 2016

I'm a bit busy this week but the info from #5296 should help me write the test case, hopefully this weekend.

@gaearon
Copy link
Collaborator
gaearon commented Jun 26, 2016

I’m going to close this for inactivity.
If you’d like to get this fixed please:

  • Including a test case that reproduces the error.
  • If you can, please try to fix it in a way that fixes the cause of the error (e.g. a mistaken assumption) rather than plugging a hole like this PR does. It is not at all obvious why ref would be undefined here, so defensive programming will only hide more bugs and edge cases IMO.

Thanks!

@gaearon gaearon closed this Jun 26, 2016
@gaearon
Copy link
Collaborator
gaearon commented Jun 26, 2016

To clarify my points, since you say

If the component has unmounted before a transition completes, sometimes the ref is undefined therefore it will throw.

we would need to see a case where this happens and fix the transition child that invokes the callback despite being unmounted. We should be canceling that callback but if we don’t (in this case?), we should fix it there instead.

@jrowny
Copy link
Author
jrowny commented Jun 27, 2016

@gaearon
The code you linked cancels a timeout, which works in CSSTransitionGroup, but this bug happens when you implement componentWillLeave manually, as when doing a GSAP animation... perhaps with a complicated timeline.

From the docs for componentWillLeave,

"ReactTransitionGroup will keep it in the DOM until callback is called."

So I think that's why the ref still exists... because the component can unmount without the callback being called. I did not yet have time to write a test to back this up.

But, I think the answer is to save the callback to the component instance. i.e.

componentWillLeave(callback){ 
   this.leaveCallback = callback;
   doSomeGSAPAnimation(callback); 
}

Then in componentWillUnmount you will call this.leaveCallback() if the hypothetical GSAP animation hasn't called it first.

In that case, no modification to React is needed, but perhaps better documentation that instructs the developer to explicitly clean up custom callbacks... or maybe we catch the error and notify the user of the proper way to cleanup componentWillLeave callbacks.

@gaearon
Copy link
Collaborator
gaearon commented Jun 27, 2016

This sounds correct to me. Perhaps this could be addressed by docs, PR is welcome!

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

Successfully merging this pull request may close these issues.

3 participants
0