[Fiber] Clear existing text content before inserting children#8331
[Fiber] Clear existing text content before inserting children#8331acdlite merged 1 commit intofacebook:masterfrom
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.
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.
This only gets called when there's a single text child
There was a problem hiding this comment.
That's not true because dangerouslySetInnerHTML can have multiple children.
There was a problem hiding this comment.
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
| const prevProps = current ? current.memoizedProps : null; | ||
| let nextChildren = workInProgress.pendingProps.children; | ||
| if (typeof nextChildren === 'string' || typeof nextChildren === 'number') { | ||
| const isDirectTextChild = config.shouldSetTextContent(nextProps); |
There was a problem hiding this comment.
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).