From b36e05b0af5658a9c50dd6a26e46aa08c85ea2d9 Mon Sep 17 00:00:00 2001 From: Andreas Svensson Date: Thu, 8 May 2014 17:05:52 +0200 Subject: [PATCH] Fix ReactEmptyComponent disappearing and throwing in IE8 --- src/browser/ui/ReactDefaultInjection.js | 2 +- src/browser/ui/dom/setInnerHTML.js | 12 +++++++++++- src/core/__tests__/ReactCompositeComponent-test.js | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/browser/ui/ReactDefaultInjection.js b/src/browser/ui/ReactDefaultInjection.js index abdbad93fa5..2bac15de63e 100644 --- a/src/browser/ui/ReactDefaultInjection.js +++ b/src/browser/ui/ReactDefaultInjection.js @@ -97,7 +97,7 @@ function inject() { ReactInjection.DOMProperty.injectDOMPropertyConfig(HTMLDOMPropertyConfig); ReactInjection.DOMProperty.injectDOMPropertyConfig(SVGDOMPropertyConfig); - ReactInjection.EmptyComponent.injectEmptyComponent(ReactDOM.script); + ReactInjection.EmptyComponent.injectEmptyComponent(ReactDOM.noscript); ReactInjection.Updates.injectReconcileTransaction( ReactComponentBrowserEnvironment.ReactReconcileTransaction diff --git a/src/browser/ui/dom/setInnerHTML.js b/src/browser/ui/dom/setInnerHTML.js index d3c8b63e8a4..a81caa43759 100644 --- a/src/browser/ui/dom/setInnerHTML.js +++ b/src/browser/ui/dom/setInnerHTML.js @@ -52,7 +52,17 @@ if (ExecutionEnvironment.canUseDOM) { node.parentNode.replaceChild(node, node); } - if (html.match(/^[ \r\n\t\f]/)) { + // We also implement a workaround for non-visible tags disappearing into + // thin air on IE8, this only happens if there is no visible text + // in-front of the non-visible tags. Piggyback on the whitespace fix + // and simply check if any non-visible tags appear in the source. + if (html.match(/^[ \r\n\t\f]/) || + html[0] === '<' && ( + html.indexOf(' { + it('should render null and false as a noscript tag under the hood', () => { var Component1 = React.createClass({ render: function() { return null; @@ -145,10 +145,10 @@ describe('ReactCompositeComponent', function() { var instance2 = ReactTestUtils.renderIntoDocument(); reactComponentExpect(instance1) .expectRenderedChild() - .toBeDOMComponentWithTag('script'); + .toBeDOMComponentWithTag('noscript'); reactComponentExpect(instance2) .expectRenderedChild() - .toBeDOMComponentWithTag('script'); + .toBeDOMComponentWithTag('noscript'); }); it('should still throw when rendering to undefined', () => {