-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Use comment nodes for empty components #5451
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactDOMEmptyComponent | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var DOMLazyTree = require('DOMLazyTree'); | ||
var ReactDOMComponentTree = require('ReactDOMComponentTree'); | ||
|
||
var assign = require('Object.assign'); | ||
|
||
var ReactDOMEmptyComponent = function(instantiate) { | ||
// ReactCompositeComponent uses this: | ||
this._currentElement = null; | ||
// ReactDOMComponentTree uses these: | ||
this._nativeNode = null; | ||
this._nativeParent = null; | ||
this._nativeContainerInfo = null; | ||
this._domID = null; | ||
}; | ||
assign(ReactDOMEmptyComponent.prototype, { | ||
construct: function(element) { | ||
}, | ||
mountComponent: function( | ||
transaction, | ||
nativeParent, | ||
nativeContainerInfo, | ||
context | ||
) { | ||
var domID = nativeContainerInfo._idCounter++; | ||
this._domID = domID; | ||
this._nativeParent = nativeParent; | ||
this._nativeContainerInfo = nativeContainerInfo; | ||
|
||
var nodeValue = ' react-empty: ' + this._domID + ' '; | ||
if (transaction.useCreateElement) { | ||
var ownerDocument = nativeContainerInfo._ownerDocument; | ||
var node = ownerDocument.createComment(nodeValue); | ||
ReactDOMComponentTree.precacheNode(this, node); | ||
return DOMLazyTree(node); | ||
} else { | ||
if (transaction.renderToStaticMarkup) { | ||
// Normally we'd insert a comment node, but since this is a situation | ||
// where React won't take over (static pages), we can simply return | ||
// nothing. | ||
return ''; | ||
} | ||
return '<!--' + nodeValue + '-->'; | ||
} | ||
}, | ||
receiveComponent: function() { | ||
}, | ||
getNativeNode: function() { | ||
return ReactDOMComponentTree.getNodeFromInstance(this); | ||
}, | ||
unmountComponent: function() { | ||
ReactDOMComponentTree.uncacheNode(this); | ||
}, | ||
}); | ||
|
||
module.exports = ReactDOMEmptyComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/renderers/shared/reconciler/ReactSimpleEmptyComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright 2014-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactSimpleEmptyComponent | ||
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. You don't use this anywhere… is the thinking that this would be used in RN? 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. (I even mentioned that in my PR description. ;)) |
||
*/ | ||
|
||
'use strict'; | ||
|
||
var ReactReconciler = require('ReactReconciler'); | ||
|
||
var assign = require('Object.assign'); | ||
|
||
var ReactSimpleEmptyComponent = function(placeholderElement, instantiate) { | ||
this._currentElement = null; | ||
this._renderedComponent = instantiate(placeholderElement); | ||
}; | ||
assign(ReactSimpleEmptyComponent.prototype, { | ||
construct: function(element) { | ||
}, | ||
mountComponent: function( | ||
transaction, | ||
nativeParent, | ||
nativeContainerInfo, | ||
context | ||
) { | ||
return ReactReconciler.mountComponent( | ||
this._renderedComponent, | ||
transaction, | ||
nativeParent, | ||
nativeContainerInfo, | ||
context | ||
); | ||
}, | ||
receiveComponent: function() { | ||
}, | ||
getNativeNode: function() { | ||
return ReactReconciler.getNativeNode(this._renderedComponent); | ||
}, | ||
unmountComponent: function() { | ||
ReactReconciler.unmountComponent(this._renderedComponent); | ||
this._renderedComponent = null; | ||
}, | ||
}); | ||
|
||
module.exports = ReactSimpleEmptyComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName indicates that
nodeName
should be'html'
for XHTML docs but that doesn't appear to be true in practice (for several years, the linked article there is from 2009) so this is probably safe.