From 543d2ea0635c9a1fc51b572159728c47731721a3 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 8 Dec 2016 08:32:46 -0800 Subject: [PATCH 1/2] Sync changes to ReactART (and tests) from main React repo These changes primarily include the new Fiber HostConfig methods shouldSetTextContent and resetTextContent. --- src/ReactARTFiber.js | 20 ++++++++ src/__tests__/ReactART-test.js | 92 +++++++++++++++++++--------------- 2 files changed, 72 insertions(+), 40 deletions(-) diff --git a/src/ReactARTFiber.js b/src/ReactARTFiber.js index 465d111..4e8fb68 100644 --- a/src/ReactARTFiber.js +++ b/src/ReactARTFiber.js @@ -388,6 +388,10 @@ class Surface extends Component { const ARTRenderer = ReactFiberReconciler({ appendChild(parentInstance, child) { + if (child.parentNode === parentInstance) { + child.eject(); + } + child.inject(parentInstance); }, @@ -451,6 +455,11 @@ const ARTRenderer = ReactFiberReconciler({ }, insertBefore(parentInstance, child, beforeChild) { + invariant( + child !== beforeChild, + 'ReactART: Can not insert node before itself' + ); + child.injectBefore(beforeChild); }, @@ -472,10 +481,21 @@ const ARTRenderer = ReactFiberReconciler({ // Noop }, + resetTextContent(domElement) { + // Noop + }, + scheduleAnimationCallback: window.requestAnimationFrame, scheduleDeferredCallback: window.requestIdleCallback, + shouldSetTextContent(props) { + return ( + typeof props.children === 'string' || + typeof props.children === 'number' + ); + }, + useSyncScheduling: true, }); diff --git a/src/__tests__/ReactART-test.js b/src/__tests__/ReactART-test.js index 10bd45f..cb01324 100644 --- a/src/__tests__/ReactART-test.js +++ b/src/__tests__/ReactART-test.js @@ -51,17 +51,17 @@ function testDOMNodeStructure(domNode, expectedStructure) { } } -describe('ReactART', function() { +describe('ReactART', () => { - beforeEach(function() { + beforeEach(() => { ARTCurrentMode.setCurrent(ARTSVGMode); Group = ReactART.Group; Shape = ReactART.Shape; Surface = ReactART.Surface; - TestComponent = React.createClass({ - render: function() { + TestComponent = class extends React.Component { + render() { var a = ); } - }); + }; }); - it('should have the correct lifecycle state', function() { + it('should have the correct lifecycle state', () => { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); var group = instance.refs.group; @@ -107,7 +107,7 @@ describe('ReactART', function() { expect(typeof group.indicate).toBe('function'); }); - it('should render a reasonable SVG structure in SVG mode', function() { + it('should render a reasonable SVG structure in SVG mode', () => { var instance = ; instance = ReactTestUtils.renderIntoDocument(instance); @@ -138,7 +138,7 @@ describe('ReactART', function() { testDOMNodeStructure(realNode, expectedStructure); }); - it('should be able to reorder components', function() { + it('should be able to reorder components', () => { var container = document.createElement('div'); var instance = ReactDOM.render(, container); @@ -182,19 +182,19 @@ describe('ReactART', function() { testDOMNodeStructure(realNode, expectedNewStructure); }); - it('should be able to reorder many components', function() { + it('should be able to reorder many components', () => { var container = document.createElement('div'); - var Component = React.createClass({ - render: function() { + class Component extends React.Component { + render() { var chars = this.props.chars.split(''); return ( {chars.map((text) => )} ); - }, - }); + } + } // Mini multi-child stress test: lots of reorders, some adds, some removes. var before = 'abcdefghijklmnopqrst'; @@ -210,16 +210,19 @@ describe('ReactART', function() { ReactDOM.unmountComponentAtNode(container); }); - it('renders composite with lifecycle inside group', function() { + it('renders composite with lifecycle inside group', () => { var mounted = false; - var CustomShape = React.createClass({ - render: function() { + + class CustomShape extends React.Component { + render() { return ; - }, - componentDidMount: function() { + } + + componentDidMount() { mounted = true; } - }); + } + ReactTestUtils.renderIntoDocument( @@ -230,18 +233,21 @@ describe('ReactART', function() { expect(mounted).toBe(true); }); - it('resolves refs before componentDidMount', function() { - var CustomShape = React.createClass({ - render: function() { + it('resolves refs before componentDidMount', () => { + class CustomShape extends React.Component { + render() { return ; } - }); + } + var ref = null; - var Outer = React.createClass({ - componentDidMount: function() { + + class Outer extends React.Component { + componentDidMount() { ref = this.refs.test; - }, - render: function() { + } + + render() { return ( @@ -250,26 +256,31 @@ describe('ReactART', function() { ); } - }); + } + ReactTestUtils.renderIntoDocument(); expect(ref.constructor).toBe(CustomShape); }); - it('resolves refs before componentDidUpdate', function() { - var CustomShape = React.createClass({ - render: function() { + it('resolves refs before componentDidUpdate', () => { + class CustomShape extends React.Component { + render() { return ; } - }); + } + var ref = {}; - var Outer = React.createClass({ - componentDidMount: function() { + + class Outer extends React.Component { + componentDidMount() { ref = this.refs.test; - }, - componentDidUpdate: function() { + } + + componentDidUpdate() { ref = this.refs.test; - }, - render: function() { + } + + render() { return ( @@ -278,7 +289,8 @@ describe('ReactART', function() { ); } - }); + } + var container = document.createElement('div'); ReactDOM.render(, container); expect(ref).not.toBeDefined(); @@ -286,7 +298,7 @@ describe('ReactART', function() { expect(ref.constructor).toBe(CustomShape); }); - it('adds and updates event handlers', function() { + it('adds and updates event handlers', () => { const container = document.createElement('div'); function render(onClick) { From ef973dc70b652996115cc5df87e8e7f93048f4b5 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Thu, 8 Dec 2016 12:58:57 -0800 Subject: [PATCH 2/2] Synced new 'getChildHostContext' HostConfig method (from react/pull/8490) --- src/ReactARTFiber.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ReactARTFiber.js b/src/ReactARTFiber.js index 4e8fb68..e7561ad 100644 --- a/src/ReactARTFiber.js +++ b/src/ReactARTFiber.js @@ -454,6 +454,10 @@ const ARTRenderer = ReactFiberReconciler({ // Noop }, + getChildHostContext() { + return null; + }, + insertBefore(parentInstance, child, beforeChild) { invariant( child !== beforeChild,