From 075f3043a7959934a273a9f18327f36f1f324757 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Sun, 20 Nov 2016 17:14:29 +0000 Subject: [PATCH] Update the internal Fiber on the DOM node to always be the current We need this to safely extract the current event listeners from the props. Unfortunately, we are still not safe to use the return pointer since it may not point to the current tree when the Fiber is reused. So this is not fully done yet. --- scripts/fiber/tests-failing.txt | 15 --------------- scripts/fiber/tests-passing-except-dev.txt | 6 ++++++ scripts/fiber/tests-passing.txt | 19 +++++++++++++------ src/renderers/dom/fiber/ReactDOMFiber.js | 10 +++++++++- .../dom/fiber/wrappers/ReactDOMFiberInput.js | 1 - .../shared/fiber/ReactFiberCommitWork.js | 2 +- .../shared/fiber/ReactFiberReconciler.js | 2 +- .../shared/shared/event/EventPluginHub.js | 5 ++++- 8 files changed, 34 insertions(+), 26 deletions(-) diff --git a/scripts/fiber/tests-failing.txt b/scripts/fiber/tests-failing.txt index 4f4a93eb60..5a1923f10a 100644 --- a/scripts/fiber/tests-failing.txt +++ b/scripts/fiber/tests-failing.txt @@ -24,21 +24,6 @@ src/renderers/art/__tests__/ReactART-test.js * resolves refs before componentDidMount * resolves refs before componentDidUpdate -src/renderers/dom/shared/__tests__/ReactBrowserEventEmitter-test.js -* should store a listener correctly -* should retrieve a listener correctly -* should clear all handlers when asked to -* should invoke a simple handler registered on a node -* should not invoke handlers if ReactBrowserEventEmitter is disabled -* should bubble simply -* should continue bubbling if an error is thrown -* should set currentTarget -* should not stopPropagation if false is returned -* should have mouse enter simulated by test utils -* should infer onTouchTap from a touchStart/End -* should infer onTouchTap from when dragging below threshold -* should bubble onTouchTap - src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js * should update styles when mutating style object * should warn when mutating style diff --git a/scripts/fiber/tests-passing-except-dev.txt b/scripts/fiber/tests-passing-except-dev.txt index 247e5287cb..3e077e6251 100644 --- a/scripts/fiber/tests-passing-except-dev.txt +++ b/scripts/fiber/tests-passing-except-dev.txt @@ -131,9 +131,15 @@ src/renderers/shared/hooks/__tests__/ReactHostOperationHistoryHook-test.js * gets recorded for composite roots * gets recorded when a native is mounted deeply instead of null * gets recorded during mount +* gets recorded during an update +* gets ignored if the styles are shallowly equal * gets recorded during mount +* gets recorded during an update +* gets recorded as a removal during an update * gets recorded during mount +* gets recorded during an update * gets recorded during mount +* gets recorded during an update * gets recorded during an update from text content * gets recorded during an update from html * gets recorded during an update from children diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 9a03e57d22..20c2a72f3c 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -534,14 +534,27 @@ src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js * should support custom attributes src/renderers/dom/shared/__tests__/ReactBrowserEventEmitter-test.js +* should store a listener correctly +* should retrieve a listener correctly +* should clear all handlers when asked to +* should invoke a simple handler registered on a node +* should not invoke handlers if ReactBrowserEventEmitter is disabled +* should bubble simply +* should continue bubbling if an error is thrown +* should set currentTarget * should support stopPropagation() * should stop after first dispatch if stopPropagation +* should not stopPropagation if false is returned * should invoke handlers that were removed while bubbling * should not invoke newly inserted handlers while bubbling +* should have mouse enter simulated by test utils +* should infer onTouchTap from a touchStart/End +* should infer onTouchTap from when dragging below threshold * should not onTouchTap from when dragging beyond threshold * should listen to events only once * should work with event plugins without dependencies * should work with event plugins with dependencies +* should bubble onTouchTap * should not crash ensureScrollValueMonitoring when createEvent returns null src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -1160,12 +1173,6 @@ src/renderers/shared/hooks/__tests__/ReactComponentTreeHook-test.native.js src/renderers/shared/hooks/__tests__/ReactHostOperationHistoryHook-test.js * gets ignored for composite roots that return null -* gets recorded during an update -* gets ignored if the styles are shallowly equal -* gets recorded during an update -* gets recorded as a removal during an update -* gets recorded during an update -* gets recorded during an update * gets ignored if new text is equal * gets ignored if new text is equal * gets ignored if the type has not changed diff --git a/src/renderers/dom/fiber/ReactDOMFiber.js b/src/renderers/dom/fiber/ReactDOMFiber.js index 4cc6c2ac91..ffd4a75244 100644 --- a/src/renderers/dom/fiber/ReactDOMFiber.js +++ b/src/renderers/dom/fiber/ReactDOMFiber.js @@ -104,9 +104,17 @@ var DOMRenderer = ReactFiberReconciler({ return true; }, - commitUpdate(domElement : Instance, oldProps : Props, newProps : Props) : void { + commitUpdate( + domElement : Instance, + oldProps : Props, + newProps : Props, + internalInstanceHandle : Object + ) : void { var type = domElement.tagName.toLowerCase(); // HACK var root = document.body; // HACK + // Update the internal instance handle so that we know which props are + // the current ones. + precacheFiberNode(internalInstanceHandle, domElement); updateProperties(domElement, type, oldProps, newProps, root); }, diff --git a/src/renderers/dom/fiber/wrappers/ReactDOMFiberInput.js b/src/renderers/dom/fiber/wrappers/ReactDOMFiberInput.js index 67e859bd07..8b5b4121ac 100644 --- a/src/renderers/dom/fiber/wrappers/ReactDOMFiberInput.js +++ b/src/renderers/dom/fiber/wrappers/ReactDOMFiberInput.js @@ -293,7 +293,6 @@ function updateNamedCousins(rootNode, props) { // That's probably okay; we don't support it just as we don't support // mixing React radio buttons with non-React ones. var otherInstance = ReactDOMComponentTree.getInstanceFromNode(otherNode); - // TODO: Ensure that otherInstance is the current Fiber instead of wip. invariant( otherInstance, 'ReactDOMInput: Mixing React and non-React radio inputs with the ' + diff --git a/src/renderers/shared/fiber/ReactFiberCommitWork.js b/src/renderers/shared/fiber/ReactFiberCommitWork.js index 6886f5ce2e..be8f661da4 100644 --- a/src/renderers/shared/fiber/ReactFiberCommitWork.js +++ b/src/renderers/shared/fiber/ReactFiberCommitWork.js @@ -282,7 +282,7 @@ module.exports = function( // Commit the work prepared earlier. const newProps = finishedWork.memoizedProps; const oldProps = current.memoizedProps; - commitUpdate(instance, oldProps, newProps); + commitUpdate(instance, oldProps, newProps, finishedWork); } detachRefIfNeeded(current, finishedWork); return; diff --git a/src/renderers/shared/fiber/ReactFiberReconciler.js b/src/renderers/shared/fiber/ReactFiberReconciler.js index b1344c4121..8b13bcdd5b 100644 --- a/src/renderers/shared/fiber/ReactFiberReconciler.js +++ b/src/renderers/shared/fiber/ReactFiberReconciler.js @@ -54,7 +54,7 @@ export type HostConfig = { createInstance(type : T, props : P, children : HostChildren, internalInstanceHandle : OpaqueNode) : I, prepareUpdate(instance : I, oldProps : P, newProps : P) : boolean, - commitUpdate(instance : I, oldProps : P, newProps : P) : void, + commitUpdate(instance : I, oldProps : P, newProps : P, internalInstanceHandle : OpaqueNode) : void, createTextInstance(text : string, internalInstanceHandle : OpaqueNode) : TI, commitTextUpdate(textInstance : TI, oldText : string, newText : string) : void, diff --git a/src/renderers/shared/shared/event/EventPluginHub.js b/src/renderers/shared/shared/event/EventPluginHub.js index efd13e7169..4023354278 100644 --- a/src/renderers/shared/shared/event/EventPluginHub.js +++ b/src/renderers/shared/shared/event/EventPluginHub.js @@ -127,7 +127,10 @@ var EventPluginHub = { // live here; needs to be moved to a better place soon if (typeof inst.tag === 'number') { // TODO: This is not safe because we might want the *other* Fiber's - // props depending on which is the current one. + // props depending on which is the current one. This will usually be the + // current Fiber but if we're walking up the tree using TreeTraversal for + // bubbling, we will not be guaranteed to walk up the current tree when + // a Fiber has been reused. const props = inst.memoizedProps; listener = props[registrationName]; if (shouldPreventMouseEvent(registrationName, inst.type, props)) {