diff --git a/src/browser/ReactComponentBrowserEnvironment.js b/src/browser/ReactComponentBrowserEnvironment.js index 12e4b593169..39c290eb6f0 100644 --- a/src/browser/ReactComponentBrowserEnvironment.js +++ b/src/browser/ReactComponentBrowserEnvironment.js @@ -20,6 +20,7 @@ "use strict"; +var DOMNodeTypes = require('DOMNodeTypes'); var ReactDOMIDOperations = require('ReactDOMIDOperations'); var ReactMarkupChecksum = require('ReactMarkupChecksum'); var ReactMount = require('ReactMount'); @@ -30,10 +31,6 @@ var getReactRootElementInContainer = require('getReactRootElementInContainer'); var invariant = require('invariant'); -var ELEMENT_NODE_TYPE = 1; -var DOC_NODE_TYPE = 9; - - /** * Abstracts away all functionality of `ReactComponent` requires knowledge of * the browser context. @@ -66,8 +63,9 @@ var ReactComponentBrowserEnvironment = { function(markup, container, shouldReuseMarkup) { invariant( container && ( - container.nodeType === ELEMENT_NODE_TYPE || - container.nodeType === DOC_NODE_TYPE + container.nodeType === DOMNodeTypes.ELEMENT || + container.nodeType === DOMNodeTypes.DOC || + container.nodeType === DOMNodeTypes.SHADOW_ROOT ), 'mountComponentIntoNode(...): Target container is not valid.' ); @@ -79,7 +77,7 @@ var ReactComponentBrowserEnvironment = { return; } else { invariant( - container.nodeType !== DOC_NODE_TYPE, + container.nodeType !== DOMNodeTypes.DOC, 'You\'re trying to render a component to the document using ' + 'server rendering but the checksum was invalid. This usually ' + 'means you rendered a different component type or props on ' + @@ -106,7 +104,7 @@ var ReactComponentBrowserEnvironment = { } invariant( - container.nodeType !== DOC_NODE_TYPE, + container.nodeType !== DOMNodeTypes.DOC, 'You\'re trying to render a component to the document but ' + 'you didn\'t use server rendering. We can\'t do this ' + 'without using server rendering due to cross-browser quirks. ' + diff --git a/src/browser/ReactDOMComponent.js b/src/browser/ReactDOMComponent.js index 6ac4177b0c9..054589a4d8f 100644 --- a/src/browser/ReactDOMComponent.js +++ b/src/browser/ReactDOMComponent.js @@ -20,6 +20,7 @@ "use strict"; var CSSPropertyOperations = require('CSSPropertyOperations'); +var DOMNodeTypes = require('DOMNodeTypes'); var DOMProperty = require('DOMProperty'); var DOMPropertyOperations = require('DOMPropertyOperations'); var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin'); @@ -44,8 +45,6 @@ var CONTENT_TYPES = {'string': true, 'number': true}; var STYLE = keyOf({style: null}); -var ELEMENT_NODE_TYPE = 1; - /** * @param {?object} props */ @@ -68,7 +67,7 @@ function assertValidProps(props) { function putListener(id, registrationName, listener, transaction) { var container = ReactMount.findReactContainerForID(id); if (container) { - var doc = container.nodeType === ELEMENT_NODE_TYPE ? + var doc = container.nodeType === DOMNodeTypes.ELEMENT ? container.ownerDocument : container; listenTo(registrationName, doc); diff --git a/src/browser/ReactMount.js b/src/browser/ReactMount.js index 1075f15cb63..4412c8d2c46 100644 --- a/src/browser/ReactMount.js +++ b/src/browser/ReactMount.js @@ -18,6 +18,7 @@ "use strict"; +var DOMNodeTypes = require('DOMNodeTypes'); var DOMProperty = require('DOMProperty'); var ReactEventEmitter = require('ReactEventEmitter'); var ReactInstanceHandles = require('ReactInstanceHandles'); @@ -33,9 +34,6 @@ var SEPARATOR = ReactInstanceHandles.SEPARATOR; var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME; var nodeCache = {}; -var ELEMENT_NODE_TYPE = 1; -var DOC_NODE_TYPE = 9; - /** Mapping from reactRootID to React component instance. */ var instancesByReactRootID = {}; @@ -269,8 +267,9 @@ var ReactMount = { _registerComponent: function(nextComponent, container) { invariant( container && ( - container.nodeType === ELEMENT_NODE_TYPE || - container.nodeType === DOC_NODE_TYPE + container.nodeType === DOMNodeTypes.ELEMENT || + container.nodeType === DOMNodeTypes.DOC || + container.nodeType === DOMNodeTypes.SHADOW_ROOT ), '_registerComponent(...): Target container is not a DOM element.' ); @@ -444,7 +443,7 @@ var ReactMount = { unmountComponentFromNode: function(instance, container) { instance.unmountComponent(); - if (container.nodeType === DOC_NODE_TYPE) { + if (container.nodeType === DOMNodeTypes.DOC) { container = container.documentElement; } diff --git a/src/browser/dom/DOMNodeTypes.js b/src/browser/dom/DOMNodeTypes.js new file mode 100644 index 00000000000..a2c4e7dfae2 --- /dev/null +++ b/src/browser/dom/DOMNodeTypes.js @@ -0,0 +1,36 @@ +/** + * Copyright 2013-2014 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @providesModule DOMNodeTypes + * @typechecks static-only + */ + +/*jslint evil: true */ + +"use strict"; + +/** + * A collection of `nodeType` values. + * + * @type {object} + * @internal + */ +var DOMNodeTypes = { + ELEMENT: 1, + DOC: 9, + SHADOW_ROOT: 11 +}; + +module.exports = DOMNodeTypes; diff --git a/src/browser/getReactRootElementInContainer.js b/src/browser/getReactRootElementInContainer.js index 3ecf18194dc..ff8d88c6b55 100644 --- a/src/browser/getReactRootElementInContainer.js +++ b/src/browser/getReactRootElementInContainer.js @@ -18,7 +18,7 @@ "use strict"; -var DOC_NODE_TYPE = 9; +var DOMNodeTypes = require('DOMNodeTypes'); /** * @param {DOMElement|DOMDocument} container DOM element that may contain @@ -30,7 +30,7 @@ function getReactRootElementInContainer(container) { return null; } - if (container.nodeType === DOC_NODE_TYPE) { + if (container.nodeType === DOMNodeTypes.DOC) { return container.documentElement; } else { return container.firstChild; diff --git a/src/browser/putDOMComponentListener.js b/src/browser/putDOMComponentListener.js index bad4387e7cc..5674477a0bb 100644 --- a/src/browser/putDOMComponentListener.js +++ b/src/browser/putDOMComponentListener.js @@ -18,17 +18,16 @@ "use strict"; +var DOMNodeTypes = require('DOMNodeTypes'); var ReactEventEmitter = require('ReactEventEmitter'); var ReactMount = require('ReactMount'); var listenTo = ReactEventEmitter.listenTo; -var ELEMENT_NODE_TYPE = 1; - function putDOMComponentListener(id, registrationName, listener) { var container = ReactMount.findReactContainerForID(id); if (container) { - var doc = container.nodeType === ELEMENT_NODE_TYPE ? + var doc = container.nodeType === DOMNodeTypes.ELEMENT ? container.ownerDocument : container; listenTo(registrationName, doc);