-
Notifications
You must be signed in to change notification settings - Fork 49.2k
[Fiber] Clear existing text content before inserting children #8331
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
Conversation
Here's a description of what I've added:
|
aa6a4ea
to
6ba7a1a
Compare
}, | ||
|
||
resetTextContent(domElement : Instance) : void { | ||
domElement.textContent = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're concerned with performance then IIRC setting textContent or innerHTML is unintuitively significantly slower than simply clearing the children one by one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only gets called when there's a single text child
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not true because dangerouslySetInnerHTML
can have multiple children.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right that's true
6ba7a1a
to
25e7cbd
Compare
Ok, accepting this but not the things it build on top of. So this will either have to wait or rebase on top of master. |
Fixes a bug when updating from a single text child (or dangerouslySetInnerHTML) to regular children, where the previous text content never gets deleted.
25e7cbd
to
0d7225a
Compare
let nextChildren = workInProgress.pendingProps.children; | ||
if (typeof nextChildren === 'string' || typeof nextChildren === 'number') { | ||
const isDirectTextChild = config.shouldSetTextContent(nextProps); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This should've been cached in a local variable above instead of using the object form.
Just a small feedback after implementing createInstance(type, props) {
return new (components.get(type))(props);
}
createTextInstance(text) {
return new (components.get('text'))({ text });
}
shouldSetTextContent(type, props) {
return type === 'text';
} |
Fixes a bug when updating from a single text child (or dangerouslySetInnerHTML) to regular children, where the previous text content never gets deleted.
Fixes a bug when updating from a single text child (or dangerouslySetInnerHTML) to regular children, where the previous text content never gets deleted.
Fixes a bug when updating from a single text child (or
dangerouslySetInnerHTML
) to regular children, where the previous text content never gets deleted.Based on #8304 (compare view).