mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Get the "current" Fiber from each node along the path
This fixes the issue where using the .return pointer isn't guaranteed to return the current Fiber so we might read the wrong props when we try to get the current event.
This commit is contained in:
@@ -27,10 +27,6 @@ src/renderers/art/__tests__/ReactART-test.js
|
||||
src/renderers/dom/__tests__/ReactDOMProduction-test.js
|
||||
* should throw with an error code in production
|
||||
|
||||
src/renderers/dom/shared/__tests__/ReactBrowserEventEmitter-test.js
|
||||
* should bubble to the right handler after an update
|
||||
* should invoke handlers that were removed while bubbling
|
||||
|
||||
src/renderers/dom/shared/__tests__/ReactDOM-test.js
|
||||
* throws in render() if the mount callback is not a function
|
||||
* throws in render() if the update callback is not a function
|
||||
|
||||
@@ -556,11 +556,13 @@ src/renderers/dom/shared/__tests__/ReactBrowserEventEmitter-test.js
|
||||
* should invoke a simple handler registered on a node
|
||||
* should not invoke handlers if ReactBrowserEventEmitter is disabled
|
||||
* should bubble simply
|
||||
* should bubble to the right handler after an update
|
||||
* 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
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
'use strict';
|
||||
|
||||
var { HostComponent } = require('ReactTypeOfWork');
|
||||
var { getNodeFromInstance, getInstanceFromNode } = require('EventPluginUtils');
|
||||
|
||||
function getParent(inst) {
|
||||
if (inst._hostParent !== undefined) {
|
||||
@@ -22,9 +23,18 @@ function getParent(inst) {
|
||||
inst = inst.return;
|
||||
// TODO: If this is a HostRoot we might want to bail out.
|
||||
// That is depending on if we want nested subtrees (layers) to bubble
|
||||
// events to their parent.
|
||||
// events to their parent. We could also go through parentNode on the
|
||||
// host node but that wouldn't work for React Native and doesn't let us
|
||||
// do the portal feature.
|
||||
} while (inst && inst.tag !== HostComponent);
|
||||
return inst;
|
||||
// Going through the Host Node will guarantee that we get the "current"
|
||||
// Fiber, instead of the alternate because that pointer is updated when
|
||||
// props update.
|
||||
// TODO: This is a bit hacky and possibly slow. We should ideally have
|
||||
// something in the reconciler that allow us to do this safely.
|
||||
if (inst) {
|
||||
return getInstanceFromNode(getNodeFromInstance(inst));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -126,11 +126,6 @@ var EventPluginHub = {
|
||||
// TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
|
||||
// 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. 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)) {
|
||||
|
||||
Reference in New Issue
Block a user