diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index 85a13ca7c62..cdfe329eb99 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -62,9 +62,6 @@ src/renderers/dom/shared/__tests__/ReactRenderDocument-test.js * should throw on full document render w/ no markup * supports findDOMNode on full-page components -src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js -* should control a value in reentrant events - src/renderers/shared/__tests__/ReactPerf-test.js * should count no-op update as waste * should count no-op update in child as waste diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index bf0af18dfd3..5a869afbc99 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -859,6 +859,7 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMIframe-test.js src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js * should properly control a value even if no event listener exists +* should control a value in reentrant events * should control values in reentrant events with different targets * should display `defaultValue` of number 0 * only assigns defaultValue if it changes diff --git a/src/renderers/dom/shared/eventPlugins/ChangeEventPlugin.js b/src/renderers/dom/shared/eventPlugins/ChangeEventPlugin.js index 4c8fee1e2d6..dc777a38efc 100644 --- a/src/renderers/dom/shared/eventPlugins/ChangeEventPlugin.js +++ b/src/renderers/dom/shared/eventPlugins/ChangeEventPlugin.js @@ -52,7 +52,7 @@ function createAndAccumulateChangeEvent(inst, nativeEvent, target) { ); event.type = 'change'; // Flag this event loop as needing state restore. - ReactControlledComponent.enqueueStateRestore(inst); + ReactControlledComponent.enqueueStateRestore(target); EventPropagators.accumulateTwoPhaseDispatches(event); return event; } diff --git a/src/renderers/shared/shared/event/ReactControlledComponent.js b/src/renderers/shared/shared/event/ReactControlledComponent.js index 29457eb0791..7c468000ff7 100644 --- a/src/renderers/shared/shared/event/ReactControlledComponent.js +++ b/src/renderers/shared/shared/event/ReactControlledComponent.js @@ -11,6 +11,8 @@ 'use strict'; +var EventPluginUtils = require('EventPluginUtils'); + var invariant = require('invariant'); // Use to restore controlled state after a change event has fired. @@ -28,7 +30,14 @@ var ReactControlledComponentInjection = { var restoreTarget = null; var restoreQueue = null; -function restoreStateOfTarget(internalInstance) { +function restoreStateOfTarget(target) { + // We perform this translation at the end of the event loop so that we + // always receive the correct fiber here + var internalInstance = EventPluginUtils.getInstanceFromNode(target); + if (!internalInstance) { + // Unmounted + return; + } if (typeof internalInstance.tag === 'number') { invariant( fiberHostComponent && @@ -36,7 +45,6 @@ function restoreStateOfTarget(internalInstance) { 'Fiber needs to be injected to handle a fiber target for controlled ' + 'events.' ); - // TODO: Ensure that this instance is the current one. Props needs to be correct. fiberHostComponent.restoreControlledState( internalInstance.stateNode, internalInstance.type, diff --git a/src/test/ReactTestUtils.js b/src/test/ReactTestUtils.js index 55ea9eeb747..50a50b95dae 100644 --- a/src/test/ReactTestUtils.js +++ b/src/test/ReactTestUtils.js @@ -484,7 +484,7 @@ function makeSimulator(eventType) { ReactGenericBatching.batchedUpdates(function() { // Normally extractEvent enqueues a state restore, but we'll just always // do that since we we're by-passing it here. - ReactControlledComponent.enqueueStateRestore(targetInst); + ReactControlledComponent.enqueueStateRestore(node); EventPluginHub.enqueueEvents(event); EventPluginHub.processEventQueue(true);