-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Fix reconciling when switching to/from innerHTML #378
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,6 @@ var registrationNames = ReactEventEmitter.registrationNames; | |
| // For quickly matching children type, to test if can be treated as content. | ||
| var CONTENT_TYPES = {'string': true, 'number': true}; | ||
|
|
||
| var DANGEROUSLY_SET_INNER_HTML = keyOf({dangerouslySetInnerHTML: null}); | ||
| var STYLE = keyOf({style: null}); | ||
|
|
||
| /** | ||
|
|
@@ -231,15 +230,11 @@ ReactNativeComponent.Mixin = { | |
| styleUpdates[styleName] = ''; | ||
| } | ||
| } | ||
| } else if (propKey === DANGEROUSLY_SET_INNER_HTML) { | ||
| // http://jsperf.com/emptying-speed | ||
| ReactComponent.DOMIDOperations.updateTextContentByID( | ||
| this._rootNodeID, | ||
| '' | ||
| ); | ||
| } else if (registrationNames[propKey]) { | ||
| deleteListener(this._rootNodeID, propKey); | ||
| } else { | ||
| } else if ( | ||
| DOMProperty.isStandardName[propKey] || | ||
| DOMProperty.isCustomAttribute(propKey)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds an extra regex eval in a hot code path. I wonder if that's a real perf issue and if memoization would help.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Updating already checked isCustomAttribute, I just made deleting do it too.)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, seems fine. |
||
| ReactComponent.DOMIDOperations.deletePropertyByID( | ||
| this._rootNodeID, | ||
| propKey | ||
|
|
@@ -277,15 +272,6 @@ ReactNativeComponent.Mixin = { | |
| // Relies on `updateStylesByID` not mutating `styleUpdates`. | ||
| styleUpdates = nextProp; | ||
| } | ||
| } else if (propKey === DANGEROUSLY_SET_INNER_HTML) { | ||
| var lastHtml = lastProp && lastProp.__html; | ||
| var nextHtml = nextProp && nextProp.__html; | ||
| if (lastHtml !== nextHtml) { | ||
| ReactComponent.DOMIDOperations.updateInnerHTMLByID( | ||
| this._rootNodeID, | ||
| nextProp | ||
| ); | ||
| } | ||
| } else if (registrationNames[propKey]) { | ||
| putListener(this._rootNodeID, propKey, nextProp); | ||
| } else if ( | ||
|
|
@@ -316,31 +302,45 @@ ReactNativeComponent.Mixin = { | |
| _updateDOMChildren: function(lastProps, transaction) { | ||
| var nextProps = this.props; | ||
|
|
||
| var lastUsedContent = | ||
| var lastContent = | ||
| CONTENT_TYPES[typeof lastProps.children] ? lastProps.children : null; | ||
| var contentToUse = | ||
| var nextContent = | ||
| CONTENT_TYPES[typeof nextProps.children] ? nextProps.children : null; | ||
|
|
||
| var lastHtml = | ||
| lastProps.dangerouslySetInnerHTML && | ||
| lastProps.dangerouslySetInnerHTML.__html; | ||
| var nextHtml = | ||
| nextProps.dangerouslySetInnerHTML && | ||
| nextProps.dangerouslySetInnerHTML.__html; | ||
|
|
||
| // Note the use of `!=` which checks for null or undefined. | ||
| var lastChildren = lastContent != null ? null : lastProps.children; | ||
| var nextChildren = nextContent != null ? null : nextProps.children; | ||
|
|
||
| var lastUsedChildren = | ||
| lastUsedContent != null ? null : lastProps.children; | ||
| var childrenToUse = contentToUse != null ? null : nextProps.children; | ||
| // If we're switching from children to content/html or vice versa, remove | ||
| // the old content | ||
| var lastHasContentOrHtml = lastContent != null || lastHtml != null; | ||
| var nextHasContentOrHtml = nextContent != null || nextHtml != null; | ||
| if (lastChildren != null && nextChildren == null) { | ||
| this.updateChildren(null, transaction); | ||
| } else if (lastHasContentOrHtml && !nextHasContentOrHtml) { | ||
| this.updateTextContent(''); | ||
| } | ||
|
|
||
| if (contentToUse != null) { | ||
| var childrenRemoved = lastUsedChildren != null && childrenToUse == null; | ||
| if (childrenRemoved) { | ||
| this.updateChildren(null, transaction); | ||
| } | ||
| if (lastUsedContent !== contentToUse) { | ||
| this.updateTextContent('' + contentToUse); | ||
| if (nextContent != null) { | ||
| if (lastContent !== nextContent) { | ||
| this.updateTextContent('' + nextContent); | ||
| } | ||
| } else { | ||
| var contentRemoved = lastUsedContent != null && contentToUse == null; | ||
| if (contentRemoved) { | ||
| this.updateTextContent(''); | ||
| } else if (nextHtml != null) { | ||
| if (lastHtml !== nextHtml) { | ||
| ReactComponent.DOMIDOperations.updateInnerHTMLByID( | ||
| this._rootNodeID, | ||
| nextHtml | ||
| ); | ||
| } | ||
| this.updateChildren(flattenChildren(nextProps.children), transaction); | ||
| } else if (nextChildren != null) { | ||
| this.updateChildren(flattenChildren(nextChildren), transaction); | ||
| } | ||
| }, | ||
|
|
||
|
|
||
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.
The comment for this method is no longer correct, can you fix it?
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.
Done.