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

Do not reset inner html for null children #8520

Merged

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Dec 7, 2016

This is required to support certain third party scripts as well as other fiber renderers (eg the new ReactART renderer).

Brian Vaughn added 2 commits December 7, 2016 12:06
This is required to support certain third party scripts as well as other fiber renderers (eg the new ReactART renderer)
if (isDirectTextChild) {
// We special case a direct text child of a host node. This is a common
// case. We won't handle it as a reified child. We will instead handle
// this in the host environment that also have access to this prop. That
// avoids allocating another HostText fiber and traversing it.
nextChildren = null;
} else if (prevProps && (
shouldSetTextContent(prevProps) ||
prevProps.children === null ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I think the reason I added these additional checks is to support the case where we switch from a direct text child to an empty child (null, undefined, or boolean). So these checks should actually be comparing nextProps.children, not prevProps.children.

Could you add a test for these cases? It's my fault those don't already exist :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case, shouldSetTextContent(prevProps) would be true right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you add a test for these cases? It's my fault those don't already exist :)

Yup, sure. I'll add another test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this what you had in mind, @acdlite?

expect(container.firstChild.innerHTML).toEqual('bonjour');

ReactDOM.render(<div />, container);
expect(container.firstChild.innerHTML).toEqual('bonjour');
Copy link
Collaborator

Choose a reason for hiding this comment

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

You verified this failed before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aye, this test fails if you revert the change to ReactFiberBeginWork.

@bvaughn bvaughn merged commit 9a31391 into facebook:master Dec 7, 2016
@bvaughn bvaughn deleted the do-not-reset-inner-html-for-null-children branch December 7, 2016 23:35
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.

4 participants