From fc341c55372d8672d267ef023bb19ce669a6794a Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Tue, 2 Jun 2015 17:23:04 -0700 Subject: [PATCH] Inline createFullPageComponent in ReactDOMComponent --- .../__tests__/ReactRenderDocument-test.js | 2 +- .../wrappers/createFullPageComponent.js | 58 ------------------- src/renderers/dom/shared/ReactDOMComponent.js | 19 ++++++ .../dom/shared/ReactDefaultInjection.js | 8 --- 4 files changed, 20 insertions(+), 67 deletions(-) delete mode 100644 src/renderers/dom/client/wrappers/createFullPageComponent.js diff --git a/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js b/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js index 0212ecad8a..667f73d46d 100644 --- a/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js +++ b/src/renderers/dom/client/__tests__/ReactRenderDocument-test.js @@ -20,7 +20,7 @@ var getTestDocument; var testDocument; var UNMOUNT_INVARIANT_MESSAGE = - 'Invariant Violation: ReactFullPageComponenthtml tried to unmount. ' + + 'Invariant Violation: tried to unmount. ' + 'Because of cross-browser quirks it is impossible to unmount some ' + 'top-level components (eg , , and ) reliably and ' + 'efficiently. To fix this, have a single top-level component that ' + diff --git a/src/renderers/dom/client/wrappers/createFullPageComponent.js b/src/renderers/dom/client/wrappers/createFullPageComponent.js deleted file mode 100644 index ede4240e97..0000000000 --- a/src/renderers/dom/client/wrappers/createFullPageComponent.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright 2013-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 createFullPageComponent - * @typechecks - */ - -'use strict'; - -// Defeat circular references by requiring this directly. -var ReactClass = require('ReactClass'); -var ReactElement = require('ReactElement'); - -var invariant = require('invariant'); - -/** - * Create a component that will throw an exception when unmounted. - * - * Components like and can't be removed or added - * easily in a cross-browser way, however it's valuable to be able to - * take advantage of React's reconciliation for styling and - * management. So we just document it and throw in dangerous cases. - * - * @param {string} tag The tag to wrap - * @return {function} convenience constructor of new component - */ -function createFullPageComponent(tag) { - var elementFactory = ReactElement.createFactory(tag); - - var FullPageComponent = ReactClass.createClass({ - tagName: tag.toUpperCase(), - displayName: 'ReactFullPageComponent' + tag, - - componentWillUnmount: function() { - invariant( - false, - '%s tried to unmount. Because of cross-browser quirks it is ' + - 'impossible to unmount some top-level components (eg <html>, <head>, ' + - 'and <body>) reliably and efficiently. To fix this, have a single ' + - 'top-level component that never unmounts render these elements.', - this.constructor.displayName - ); - }, - - render: function() { - return elementFactory(this.props); - }, - }); - - return FullPageComponent; -} - -module.exports = createFullPageComponent; diff --git a/src/renderers/dom/shared/ReactDOMComponent.js b/src/renderers/dom/shared/ReactDOMComponent.js index 3bde584626..9ceaf8c770 100644 --- a/src/renderers/dom/shared/ReactDOMComponent.js +++ b/src/renderers/dom/shared/ReactDOMComponent.js @@ -646,6 +646,25 @@ ReactDOMComponent.Mixin = { case 'input': ReactDOMInput.unmountWrapper(this); break; + case 'html': + case 'head': + case 'body': + /** + * Components like <html> <head> and <body> can't be removed or added + * easily in a cross-browser way, however it's valuable to be able to + * take advantage of React's reconciliation for styling and <title> + * management. So we just document it and throw in dangerous cases. + */ + invariant( + false, + '<%s> tried to unmount. Because of cross-browser quirks it is ' + + 'impossible to unmount some top-level components (eg <html>, ' + + '<head>, and <body>) reliably and efficiently. To fix this, have a ' + + 'single top-level component that never unmounts render these ' + + 'elements.', + this._tag + ); + break; } this.unmountChildren(); diff --git a/src/renderers/dom/shared/ReactDefaultInjection.js b/src/renderers/dom/shared/ReactDefaultInjection.js index 4b5793425e..b7079b85b3 100644 --- a/src/renderers/dom/shared/ReactDefaultInjection.js +++ b/src/renderers/dom/shared/ReactDefaultInjection.js @@ -45,8 +45,6 @@ var ServerReactRootIndex = require('ServerReactRootIndex'); var SimpleEventPlugin = require('SimpleEventPlugin'); var SVGDOMPropertyConfig = require('SVGDOMPropertyConfig'); -var createFullPageComponent = require('createFullPageComponent'); - function autoGenerateWrapperClass(type) { return ReactClass.createClass({ tagName: type.toUpperCase(), @@ -110,8 +108,6 @@ function inject() { autoGenerateWrapperClass ); - // This needs to happen before createFullPageComponent() otherwise the mixin - // won't be included. ReactInjection.Class.injectMixin(ReactBrowserComponentMixin); ReactInjection.NativeComponent.injectComponentClasses({ @@ -122,10 +118,6 @@ function inject() { 'option': ReactDOMOption, 'select': ReactDOMSelect, 'textarea': ReactDOMTextarea, - - 'html': createFullPageComponent('html'), - 'head': createFullPageComponent('head'), - 'body': createFullPageComponent('body'), }); ReactInjection.DOMProperty.injectDOMPropertyConfig(HTMLDOMPropertyConfig);