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

ErrorBoundaries: Initial pass at the easy case of updates #6020

Closed
wants to merge 1 commit into from

Conversation

jimfb
Copy link
Contributor

@jimfb jimfb commented Feb 11, 2016

This is a very initial pass at the easy case of updates (updates that pass through the error boundary by themselves). There are likely bugs and more testing is needed before this can be merged. Don't feel obligated to code review yet, posting mostly for visibility.

@jimfb jimfb changed the title Initial pass at the easy case of updates ErrorBoundaries: Initial pass at the easy case of updates Feb 11, 2016
@jimfb jimfb force-pushed the error-boundaries-updates branch from 8d41345 to b7c534b Compare February 11, 2016 19:24
@jimfb jimfb mentioned this pull request Feb 15, 2016
@jimfb jimfb force-pushed the error-boundaries-updates branch from b7c534b to 3745894 Compare February 17, 2016 18:58
@facebook-github-bot
Copy link

@jimfb updated the pull request.

@jimfb jimfb force-pushed the error-boundaries-updates branch from 3745894 to 60e23bf Compare February 17, 2016 22:20
@facebook-github-bot
Copy link

@jimfb updated the pull request.

@jimfb jimfb force-pushed the error-boundaries-updates branch from 60e23bf to ef84061 Compare February 17, 2016 22:32
@facebook-github-bot
Copy link

@jimfb updated the pull request.

@jimfb
Copy link
Contributor Author

jimfb commented Feb 17, 2016

cc @spicyj @sebmarkbage I think this one is now ready for review.

}
}

class InnocentParnet extends React.Component {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: Parnet -> Parent

@jimfb jimfb force-pushed the error-boundaries-updates branch 2 times, most recently from 743f081 to 27b0f58 Compare February 18, 2016 00:01
@jimfb jimfb force-pushed the error-boundaries-updates branch from 27b0f58 to d959599 Compare February 26, 2016 19:54
@jimfb
Copy link
Contributor Author

jimfb commented Feb 26, 2016

Ping @spicyj @sebmarkbage

@sebmarkbage
Copy link
Collaborator

Do we need to make a branch cut before we land?

On Feb 26, 2016, at 12:01 PM, Jim notifications@github.com wrote:

Ping @spicyj @sebmarkbage


Reply to this email directly or view it on GitHub.

@jimfb
Copy link
Contributor Author

jimfb commented Feb 27, 2016

That's probably a question for @zpao, I don't care either way (before/after branch cut). I just want to make forward progress on this diff, so we should do a CR either way.

@sebmarkbage
Copy link
Collaborator

There are mutations that happen during this phase.

https://github.com/facebook/react/blob/master/src/renderers/shared/reconciler/ReactMultiChild.js#L325

These are not applied to the underlying nodes until later:

https://github.com/facebook/react/blob/master/src/renderers/shared/reconciler/ReactMultiChild.js#L357

This will definitely leave the system in an inconsistent state.

I guess the strategy here is that we'll not touch the DOM nodes during the safe unmount and therefore it doesn't matter.

Can you add some tests that ensures that child removals, additions and reordering works when the error is thrown in the middle of all that?

checkpoint = transaction.checkpoint();

// Gracefully update to a clean state
this._updateRenderedComponentWithNextElement(transaction, context, null, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this mean that we always render null? Regardless if the component updated state.

Can you add something to your tests that checks that the error message is actually shown in the DOM, not just executed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rendering null means something. It means inserting a placeholder.

Ideally this would be unmounting safely first. Then try to mount the new child as defined by the state change and if that fails, bubble up the error one more level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inserting a placeholder is an implementation detail, not something guaranteed by React. I think my initial approach was to unmount safely first, but the issue is that you need to unmount the children but not the parent, in which case the parent's state is wrong, and the whole thing just starts introducing complicated branching logic and introducing a lot of surface area for bugs. Rendering to null was much cleaner.

@sebmarkbage
Copy link
Collaborator

Tests and the null thing.

@jimfb jimfb force-pushed the error-boundaries-updates branch from d959599 to a81ff82 Compare April 13, 2016 21:55
@jimfb
Copy link
Contributor Author

jimfb commented Apr 13, 2016

Added some tests - let me know if they don't test what you wanted. Also responded to the null thing.

@gaearon
Copy link
Collaborator

gaearon commented Apr 19, 2016

Works great!

@davidpfahler
Copy link

Just verified that this works great as illustrated by @gaearon above. I see no problems with the implementation, but I'm by no means a react internals expert. Nonetheless, can we please get this to land soon?

@vjeux
Copy link
Contributor

vjeux commented Jul 5, 2016

Closing this as there hasn't been any updates in 3 months. Feel free to comment on this one or recreate a pull request if this is something you'd like to continue.

@vjeux vjeux closed this Jul 5, 2016
@sophiebits
Copy link
Collaborator

We want to get this in probably. I'm planning to take a look at it this week.

@davidpfahler
Copy link

@vjeux @gaearon Correct me if I'm wrong, but I remember seeing on the react meeting notes that @gaearon will be tiding up React Hot Loader 3, which depends on this (i.e. ErrorBoundaries) landing.

@gaearon
Copy link
Collaborator

gaearon commented Jul 5, 2016

I plan to change it to not depend on it. This doesn't preserve state deeply anyway. I think I'll build error handling into react-proxy instead.

@davidpfahler
Copy link

@gaearon ok thx

@ghost ghost added the CLA Signed label Jul 12, 2016
@shaneosullivan
Copy link
Contributor

Any update on this? Our internal FB teams will benefit hugely when it's working

@sophiebits
Copy link
Collaborator

Sorry, been busy with the ES6 class conversion. Will try to look tomorrow.

'error handled',
'BrokenUnmount is attempting to unmount',
'BrokenUnmount is attempting to unmount',
'BrokenUnmount is attempting to unmount',
Copy link
Collaborator

Choose a reason for hiding this comment

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

A little unfortunate that we re-call componentWillUnmount on the component that already failed to unmount.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This was fixed in #6613.

@gaearon
Copy link
Collaborator

gaearon commented Oct 12, 2016

I’m rebasing and addressing comments on this in #7949.

@gaearon gaearon closed this Oct 12, 2016
Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Addressed review feedback in #6020.
Will add more tests on the top in it.

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.

8 participants