Skip to content

Commit

Permalink
Serialize children of noscript tags; fixes facebookGH-1252
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwithanm committed Mar 29, 2014
1 parent 70a8c55 commit d93280f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/browser/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var ReactDOM = mapObject({
meta: true,
meter: false,
nav: false,
noscript: false,
noscript: false, // NOTE: Injected, see `ReactDOMNoscript`.
object: false,
ol: false,
optgroup: false,
Expand Down
2 changes: 2 additions & 0 deletions src/browser/ui/ReactDefaultInjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var ReactDOMButton = require('ReactDOMButton');
var ReactDOMForm = require('ReactDOMForm');
var ReactDOMImg = require('ReactDOMImg');
var ReactDOMInput = require('ReactDOMInput');
var ReactDOMNoscript = require('ReactDOMNoscript');
var ReactDOMOption = require('ReactDOMOption');
var ReactDOMSelect = require('ReactDOMSelect');
var ReactDOMTextarea = require('ReactDOMTextarea');
Expand Down Expand Up @@ -84,6 +85,7 @@ function inject() {
form: ReactDOMForm,
img: ReactDOMImg,
input: ReactDOMInput,
noscript: ReactDOMNoscript,
option: ReactDOMOption,
select: ReactDOMSelect,
textarea: ReactDOMTextarea,
Expand Down
70 changes: 70 additions & 0 deletions src/browser/ui/dom/components/ReactDOMNoscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* 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 ReactDOMNoscript
*/

"use strict";

var ReactBrowserComponentMixin = require('ReactBrowserComponentMixin');
var ReactChildren = require('ReactChildren');
var ReactCompositeComponent = require('ReactCompositeComponent');
var ReactDOM = require('ReactDOM');
var ReactServerRendering = require('ReactServerRendering');

var invariant = require ('invariant');
var merge = require('merge');

// Store a reference to the <noscript> `ReactDOMComponent`.
var noscript = ReactDOM.noscript;

/**
* Implements a <noscript> native component that renders its children as a
* (static markup) string. This allows you to nest your components in a
* <noscript> for server-side rendering without causing reconciliation problems
* for the browser (where they would be seen as a string anyway).
*/
var ReactDOMNoscript = ReactCompositeComponent.createClass({
displayName: 'ReactDOMNoscript',
tagName: 'NOSCRIPT',

mixins: [ReactBrowserComponentMixin],

render: function() {
// Clone `this.props` so we don't mutate the input.
var props = merge(this.props);

// Note the use of `==` which checks for null or undefined.
invariant(
props.children == null || props.dangerouslySetInnerHTML == null,
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
);

if (props.children != null) {
var serializedChildren = [];
ReactChildren.forEach(this.props.children, function(child) {
serializedChildren.push(
ReactServerRendering.renderComponentToStaticMarkup(child)
);
});
props.children = null;
props.dangerouslySetInnerHTML = {__html: serializedChildren.join('')};
}

return noscript(props);
}
});

module.exports = ReactDOMNoscript;

0 comments on commit d93280f

Please sign in to comment.