@samitouri / QOS-React-2 / commits / 5c13e2ee58

Remove Stack (part 4: remove Stack-only branches and types) (#10798)

* Remove findDOMNode injection and inline it * Remove Stack-only code in ReactGenericBatching * Remove Stack-only code branches

Dan Abramov committed Oct 2, 2017 at 13:43 UTC 5c13e2ee58b88bf1668628a06dbe0109519bdb3c
30 files changed +195 -799
src/isomorphic/classic/element/ReactCurrentOwner.js
+1 -2
@@ -10,7 +10,6 @@
10
11 'use strict';
12
13 -import type {ReactInstance} from 'ReactInstanceType';
13 import type {Fiber} from 'ReactFiber';
14
15 /**
@@ -24,7 +23,7 @@ var ReactCurrentOwner = {
23 * @internal
24 * @type {ReactComponent}
25 */
27 - current: (null: null | ReactInstance | Fiber),
26 + current: (null: null | Fiber),
27 };
28
29 module.exports = ReactCurrentOwner;
src/renderers/dom/fiber/ReactDOMFiberEntry.js
+48 -11
@@ -10,7 +10,6 @@
10
11 'use strict';
12
13 -import type {Fiber} from 'ReactFiber';
13 import type {ReactNodeList} from 'ReactTypes';
14
15 require('checkReact');
@@ -28,6 +27,7 @@ var ReactInputSelection = require('ReactInputSelection');
27 var ReactInstanceMap = require('ReactInstanceMap');
28 var ReactPortal = require('ReactPortal');
29 var ReactVersion = require('ReactVersion');
30 +var {ReactCurrentOwner} = require('ReactGlobalSharedState');
31 var {injectInternals} = require('ReactFiberDevToolsHook');
32 var {
33 ELEMENT_NODE,
@@ -38,7 +38,7 @@ var {
38 } = require('HTMLNodeType');
39 var {ROOT_ATTRIBUTE_NAME} = require('DOMProperty');
40
41 -var findDOMNode = require('findDOMNode');
41 +var getComponentName = require('getComponentName');
42 var invariant = require('fbjs/lib/invariant');
43
44 var {getChildNamespace} = DOMNamespaces;
@@ -85,9 +85,6 @@ require('ReactDOMInjection');
85 ReactControlledComponent.injection.injectFiberControlledHostComponent(
86 ReactDOMFiberComponent,
87 );
88 -findDOMNode._injectFiber(function(fiber: Fiber) {
89 - return DOMRenderer.findHostInstance(fiber);
90 -});
88
89 type DOMContainer =
90 | (Element & {
@@ -232,7 +229,7 @@ var DOMRenderer = ReactFiberReconciler({
229 if (__DEV__) {
230 // TODO: take namespace into account when validating.
231 const hostContextDev = ((hostContext: any): HostContextDev);
235 - validateDOMNesting(type, null, null, hostContextDev.ancestorInfo);
232 + validateDOMNesting(type, null, hostContextDev.ancestorInfo);
233 if (
234 typeof props.children === 'string' ||
235 typeof props.children === 'number'
@@ -243,7 +240,7 @@ var DOMRenderer = ReactFiberReconciler({
240 type,
241 null,
242 );
246 - validateDOMNesting(null, string, null, ownAncestorInfo);
243 + validateDOMNesting(null, string, ownAncestorInfo);
244 }
245 parentNamespace = hostContextDev.namespace;
246 } else {
@@ -298,7 +295,7 @@ var DOMRenderer = ReactFiberReconciler({
295 type,
296 null,
297 );
301 - validateDOMNesting(null, string, null, ownAncestorInfo);
298 + validateDOMNesting(null, string, ownAncestorInfo);
299 }
300 }
301 return diffProperties(
@@ -365,7 +362,7 @@ var DOMRenderer = ReactFiberReconciler({
362 ): TextInstance {
363 if (__DEV__) {
364 const hostContextDev = ((hostContext: any): HostContextDev);
368 - validateDOMNesting(null, text, null, hostContextDev.ancestorInfo);
365 + validateDOMNesting(null, text, hostContextDev.ancestorInfo);
366 }
367 var textNode: TextInstance = createTextNode(text, rootContainerInstance);
368 precacheFiberNode(internalInstanceHandle, textNode);
@@ -675,6 +672,48 @@ function createPortal(
672 var ReactDOMFiber = {
673 createPortal,
674
675 + findDOMNode(
676 + componentOrElement: Element | ?React$Component<any, any>,
677 + ): null | Element | Text {
678 + if (__DEV__) {
679 + var owner = (ReactCurrentOwner.current: any);
680 + if (owner !== null) {
681 + var warnedAboutRefsInRender = owner.stateNode._warnedAboutRefsInRender;
682 + warning(
683 + warnedAboutRefsInRender,
684 + '%s is accessing findDOMNode inside its render(). ' +
685 + 'render() should be a pure function of props and state. It should ' +
686 + 'never access something that requires stale data from the previous ' +
687 + 'render, such as refs. Move this logic to componentDidMount and ' +
688 + 'componentDidUpdate instead.',
689 + getComponentName(owner) || 'A component',
690 + );
691 + owner.stateNode._warnedAboutRefsInRender = true;
692 + }
693 + }
694 + if (componentOrElement == null) {
695 + return null;
696 + }
697 + if ((componentOrElement: any).nodeType === ELEMENT_NODE) {
698 + return (componentOrElement: any);
699 + }
700 +
701 + var inst = ReactInstanceMap.get(componentOrElement);
702 + if (inst) {
703 + return DOMRenderer.findHostInstance(inst);
704 + }
705 +
706 + if (typeof componentOrElement.render === 'function') {
707 + invariant(false, 'Unable to find node on an unmounted component.');
708 + } else {
709 + invariant(
710 + false,
711 + 'Element appears to be neither ReactComponent nor DOMNode. Keys: %s',
712 + Object.keys(componentOrElement),
713 + );
714 + }
715 + },
716 +
717 hydrate(element: React$Node, container: DOMContainer, callback: ?Function) {
718 // TODO: throw or warn if we couldn't hydrate?
719 return renderSubtreeIntoContainer(null, element, container, true, callback);
@@ -768,8 +807,6 @@ var ReactDOMFiber = {
807 }
808 },
809
771 - findDOMNode: findDOMNode,
772 -
810 // Temporary alias since we already shipped React 16 RC with it.
811 // TODO: remove in React 17.
812 unstable_createPortal: createPortal,
src/renderers/dom/shared/ReactDOMComponentFlags.js deleted
-16
@@ -1,16 +0,0 @@
1 -/**
2 - * Copyright (c) 2015-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule ReactDOMComponentFlags
8 - */
9 -
10 -'use strict';
11 -
12 -var ReactDOMComponentFlags = {
13 - hasCachedChildNodes: 1 << 0,
14 -};
15 -
16 -module.exports = ReactDOMComponentFlags;
src/renderers/dom/shared/ReactDOMComponentTree.js
+2 -139
@@ -9,116 +9,18 @@
9
10 'use strict';
11
12 -var DOMProperty = require('DOMProperty');
13 -var ReactDOMComponentFlags = require('ReactDOMComponentFlags');
12 var {HostComponent, HostText} = require('ReactTypeOfWork');
15 -var {ELEMENT_NODE, COMMENT_NODE} = require('HTMLNodeType');
13
14 var invariant = require('fbjs/lib/invariant');
15
19 -var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
20 -var Flags = ReactDOMComponentFlags;
21 -
16 var randomKey = Math.random().toString(36).slice(2);
23 -
17 var internalInstanceKey = '__reactInternalInstance$' + randomKey;
25 -
18 var internalEventHandlersKey = '__reactEventHandlers$' + randomKey;
19
28 -/**
29 - * Check if a given node should be cached.
30 - */
31 -function shouldPrecacheNode(node, nodeID) {
32 - return (
33 - (node.nodeType === ELEMENT_NODE &&
34 - node.getAttribute(ATTR_NAME) === '' + nodeID) ||
35 - (node.nodeType === COMMENT_NODE &&
36 - node.nodeValue === ' react-text: ' + nodeID + ' ') ||
37 - (node.nodeType === COMMENT_NODE &&
38 - node.nodeValue === ' react-empty: ' + nodeID + ' ')
39 - );
40 -}
41 -
42 -/**
43 - * Drill down (through composites and empty components) until we get a host or
44 - * host text component.
45 - *
46 - * This is pretty polymorphic but unavoidable with the current structure we have
47 - * for `_renderedChildren`.
48 - */
49 -function getRenderedHostOrTextFromComponent(component) {
50 - var rendered;
51 - while ((rendered = component._renderedComponent)) {
52 - component = rendered;
53 - }
54 - return component;
55 -}
56 -
57 -/**
58 - * Populate `_hostNode` on the rendered host/text component with the given
59 - * DOM node. The passed `inst` can be a composite.
60 - */
61 -function precacheNode(inst, node) {
62 - var hostInst = getRenderedHostOrTextFromComponent(inst);
63 - hostInst._hostNode = node;
64 - node[internalInstanceKey] = hostInst;
65 -}
66 -
20 function precacheFiberNode(hostInst, node) {
21 node[internalInstanceKey] = hostInst;
22 }
23
71 -function uncacheNode(inst) {
72 - var node = inst._hostNode;
73 - if (node) {
74 - delete node[internalInstanceKey];
75 - inst._hostNode = null;
76 - }
77 -}
78 -
79 -/**
80 - * Populate `_hostNode` on each child of `inst`, assuming that the children
81 - * match up with the DOM (element) children of `node`.
82 - *
83 - * We cache entire levels at once to avoid an n^2 problem where we access the
84 - * children of a node sequentially and have to walk from the start to our target
85 - * node every time.
86 - *
87 - * Since we update `_renderedChildren` and the actual DOM at (slightly)
88 - * different times, we could race here and see a newer `_renderedChildren` than
89 - * the DOM nodes we see. To avoid this, ReactMultiChild calls
90 - * `prepareToManageChildren` before we change `_renderedChildren`, at which
91 - * time the container's child nodes are always cached (until it unmounts).
92 - */
93 -function precacheChildNodes(inst, node) {
94 - if (inst._flags & Flags.hasCachedChildNodes) {
95 - return;
96 - }
97 - var children = inst._renderedChildren;
98 - var childNode = node.firstChild;
99 - outer: for (var name in children) {
100 - if (!children.hasOwnProperty(name)) {
101 - continue;
102 - }
103 - var childInst = children[name];
104 - var childID = getRenderedHostOrTextFromComponent(childInst)._domID;
105 - if (childID === 0) {
106 - // We're currently unmounting this child in ReactMultiChild; skip it.
107 - continue;
108 - }
109 - // We assume the child nodes are in the same order as the child instances.
110 - for (; childNode !== null; childNode = childNode.nextSibling) {
111 - if (shouldPrecacheNode(childNode, childID)) {
112 - precacheNode(childInst, childNode);
113 - continue outer;
114 - }
115 - }
116 - // We reached the end of the DOM children without finding an ID match.
117 - invariant(false, 'Unable to find element with ID %s.', childID);
118 - }
119 - inst._flags |= Flags.hasCachedChildNodes;
120 -}
121 -
24 /**
25 * Given a DOM node, return the closest ReactDOMComponent or
26 * ReactDOMTextComponent instance ancestor.
@@ -149,9 +51,6 @@ function getClosestInstanceFromNode(node) {
51 }
52 for (; node && (inst = node[internalInstanceKey]); node = parents.pop()) {
53 closest = inst;
152 - if (parents.length) {
153 - precacheChildNodes(inst, node);
154 - }
54 }
55
56 return closest;
@@ -166,18 +65,11 @@ function getInstanceFromNode(node) {
65 if (inst) {
66 if (inst.tag === HostComponent || inst.tag === HostText) {
67 return inst;
169 - } else if (inst._hostNode === node) {
170 - return inst;
68 } else {
69 return null;
70 }
71 }
175 - inst = getClosestInstanceFromNode(node);
176 - if (inst != null && inst._hostNode === node) {
177 - return inst;
178 - } else {
179 - return null;
180 - }
72 + return null;
73 }
74
75 /**
@@ -193,33 +85,7 @@ function getNodeFromInstance(inst) {
85
86 // Without this first invariant, passing a non-DOM-component triggers the next
87 // invariant for a missing parent, which is super confusing.
196 - invariant(
197 - inst._hostNode !== undefined,
198 - 'getNodeFromInstance: Invalid argument.',
199 - );
200 -
201 - if (inst._hostNode) {
202 - return inst._hostNode;
203 - }
204 -
205 - // Walk up the tree until we find an ancestor whose DOM node we have cached.
206 - var parents = [];
207 - while (!inst._hostNode) {
208 - parents.push(inst);
209 - invariant(
210 - inst._hostParent,
211 - 'React DOM tree root should always have a node reference.',
212 - );
213 - inst = inst._hostParent;
214 - }
215 -
216 - // Now parents contains each ancestor that does *not* have a cached native
217 - // node, and `inst` is the deepest ancestor that does.
218 - for (; parents.length; inst = parents.pop()) {
219 - precacheChildNodes(inst, inst._hostNode);
220 - }
221 -
222 - return inst._hostNode;
88 + invariant(false, 'getNodeFromInstance: Invalid argument.');
89 }
90
91 function getFiberCurrentPropsFromNode(node) {
@@ -234,9 +100,6 @@ var ReactDOMComponentTree = {
100 getClosestInstanceFromNode: getClosestInstanceFromNode,
101 getInstanceFromNode: getInstanceFromNode,
102 getNodeFromInstance: getNodeFromInstance,
237 - precacheChildNodes: precacheChildNodes,
238 - precacheNode: precacheNode,
239 - uncacheNode: uncacheNode,
103 precacheFiberNode: precacheFiberNode,
104 getFiberCurrentPropsFromNode,
105 updateFiberProps,
src/renderers/dom/shared/ReactDOMEventListener.js
+7 -15
@@ -31,22 +31,14 @@ function findRootContainerNode(inst) {
31 // TODO: It may be a good idea to cache this to prevent unnecessary DOM
32 // traversal, but caching is difficult to do correctly without using a
33 // mutation observer to listen for all DOM changes.
34 - if (typeof inst.tag === 'number') {
35 - while (inst.return) {
36 - inst = inst.return;
37 - }
38 - if (inst.tag !== HostRoot) {
39 - // This can happen if we're in a detached tree.
40 - return null;
41 - }
42 - return inst.stateNode.containerInfo;
43 - } else {
44 - while (inst._hostParent) {
45 - inst = inst._hostParent;
46 - }
47 - var rootNode = ReactDOMComponentTree.getNodeFromInstance(inst);
48 - return rootNode.parentNode;
34 + while (inst.return) {
35 + inst = inst.return;
36 + }
37 + if (inst.tag !== HostRoot) {
38 + // This can happen if we're in a detached tree.
39 + return null;
40 }
41 + return inst.stateNode.containerInfo;
42 }
43
44 // Used to store ancestor hierarchy in top level callback
src/renderers/dom/shared/ReactDOMFeatureFlags.js
-1
@@ -11,7 +11,6 @@
11
12 var ReactDOMFeatureFlags = {
13 fiberAsyncScheduling: false,
14 - useFiber: true,
14 };
15
16 module.exports = ReactDOMFeatureFlags;
src/renderers/dom/shared/__tests__/ReactDOMComponentTree-test.js
+2 -8
@@ -23,17 +23,11 @@ describe('ReactDOMComponentTree', () => {
23 }
24
25 function getTypeOf(instance) {
26 - if (typeof instance.tag === 'number') {
27 - return instance.type;
28 - }
29 - return instance._currentElement.type;
26 + return instance.type;
27 }
28
29 function getTextOf(instance) {
33 - if (typeof instance.tag === 'number') {
34 - return instance.memoizedProps;
35 - }
36 - return instance._stringText;
30 + return instance.memoizedProps;
31 }
32
33 beforeEach(() => {
src/renderers/dom/shared/eventPlugins/SimpleEventPlugin.js
+2 -2
@@ -34,7 +34,7 @@ import type {
34 DispatchConfig,
35 ReactSyntheticEvent,
36 } from 'ReactSyntheticEventType';
37 -import type {ReactInstance} from 'ReactInstanceType';
37 +import type {Fiber} from 'ReactFiber';
38 import type {EventTypes, PluginModule} from 'PluginModuleType';
39
40 /**
@@ -179,7 +179,7 @@ var SimpleEventPlugin: PluginModule<MouseEvent> = {
179
180 extractEvents: function(
181 topLevelType: TopLevelTypes,
182 - targetInst: ReactInstance,
182 + targetInst: Fiber,
183 nativeEvent: MouseEvent,
184 nativeEventTarget: EventTarget,
185 ): null | ReactSyntheticEvent {
src/renderers/dom/shared/findDOMNode.js deleted
-89
@@ -1,89 +0,0 @@
1 -/**
2 - * Copyright (c) 2013-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule findDOMNode
8 - * @flow
9 - */
10 -
11 -var ReactInstanceMap = require('ReactInstanceMap');
12 -var {ELEMENT_NODE} = require('HTMLNodeType');
13 -var {ReactCurrentOwner} = require('ReactGlobalSharedState');
14 -
15 -var getComponentName = require('getComponentName');
16 -var invariant = require('fbjs/lib/invariant');
17 -
18 -if (__DEV__) {
19 - var warning = require('fbjs/lib/warning');
20 -}
21 -
22 -let findFiber = function(arg) {
23 - invariant(false, 'Missing injection for fiber findDOMNode');
24 -};
25 -let findStack = function(arg) {
26 - invariant(false, 'Missing injection for stack findDOMNode');
27 -};
28 -
29 -const findDOMNode = function(
30 - componentOrElement: Element | ?React$Component<any, any>,
31 -): null | Element | Text {
32 - if (__DEV__) {
33 - var owner = (ReactCurrentOwner.current: any);
34 - if (owner !== null) {
35 - var isFiber = typeof owner.tag === 'number';
36 - var warnedAboutRefsInRender = isFiber
37 - ? owner.stateNode._warnedAboutRefsInRender
38 - : owner._warnedAboutRefsInRender;
39 - warning(
40 - warnedAboutRefsInRender,
41 - '%s is accessing findDOMNode inside its render(). ' +
42 - 'render() should be a pure function of props and state. It should ' +
43 - 'never access something that requires stale data from the previous ' +
44 - 'render, such as refs. Move this logic to componentDidMount and ' +
45 - 'componentDidUpdate instead.',
46 - getComponentName(owner) || 'A component',
47 - );
48 - if (isFiber) {
49 - owner.stateNode._warnedAboutRefsInRender = true;
50 - } else {
51 - owner._warnedAboutRefsInRender = true;
52 - }
53 - }
54 - }
55 - if (componentOrElement == null) {
56 - return null;
57 - }
58 - if ((componentOrElement: any).nodeType === ELEMENT_NODE) {
59 - return (componentOrElement: any);
60 - }
61 -
62 - var inst = ReactInstanceMap.get(componentOrElement);
63 - if (inst) {
64 - if (typeof inst.tag === 'number') {
65 - return findFiber(inst);
66 - } else {
67 - return findStack(inst);
68 - }
69 - }
70 -
71 - if (typeof componentOrElement.render === 'function') {
72 - invariant(false, 'Unable to find node on an unmounted component.');
73 - } else {
74 - invariant(
75 - false,
76 - 'Element appears to be neither ReactComponent nor DOMNode. Keys: %s',
77 - Object.keys(componentOrElement),
78 - );
79 - }
80 -};
81 -
82 -findDOMNode._injectFiber = function(fn) {
83 - findFiber = fn;
84 -};
85 -findDOMNode._injectStack = function(fn) {
86 - findStack = fn;
87 -};
88 -
89 -module.exports = findDOMNode;
src/renderers/dom/shared/validateDOMNesting.js
+2 -93
@@ -10,7 +10,6 @@
10 'use strict';
11
12 var emptyFunction = require('fbjs/lib/emptyFunction');
13 -var getComponentName = require('getComponentName');
13
14 var validateDOMNesting = emptyFunction;
15
@@ -405,83 +404,9 @@ if (__DEV__) {
404 return null;
405 };
406
408 - /**
409 - * Given a ReactCompositeComponent instance, return a list of its recursive
410 - * owners, starting at the root and ending with the instance itself.
411 - */
412 - var findOwnerStack = function(instance) {
413 - if (!instance) {
414 - return [];
415 - }
416 -
417 - var stack = [];
418 - do {
419 - stack.push(instance);
420 - } while ((instance = instance._currentElement._owner));
421 - stack.reverse();
422 - return stack;
423 - };
424 -
425 - var getOwnerInfo = function(
426 - childInstance,
427 - childTag,
428 - ancestorInstance,
429 - ancestorTag,
430 - isParent,
431 - ) {
432 - var childOwner = childInstance && childInstance._currentElement._owner;
433 - var ancestorOwner =
434 - ancestorInstance && ancestorInstance._currentElement._owner;
435 -
436 - var childOwners = findOwnerStack(childOwner);
437 - var ancestorOwners = findOwnerStack(ancestorOwner);
438 -
439 - var minStackLen = Math.min(childOwners.length, ancestorOwners.length);
440 - var i;
441 -
442 - var deepestCommon = -1;
443 - for (i = 0; i < minStackLen; i++) {
444 - if (childOwners[i] === ancestorOwners[i]) {
445 - deepestCommon = i;
446 - } else {
447 - break;
448 - }
449 - }
450 -
451 - var UNKNOWN = '(unknown)';
452 - var childOwnerNames = childOwners
453 - .slice(deepestCommon + 1)
454 - .map(inst => getComponentName(inst) || UNKNOWN);
455 - var ancestorOwnerNames = ancestorOwners
456 - .slice(deepestCommon + 1)
457 - .map(inst => getComponentName(inst) || UNKNOWN);
458 - var ownerInfo = []
459 - .concat(
460 - // If the parent and child instances have a common owner ancestor, start
461 - // with that -- otherwise we just start with the parent's owners.
462 - deepestCommon !== -1
463 - ? getComponentName(childOwners[deepestCommon]) || UNKNOWN
464 - : [],
465 - ancestorOwnerNames,
466 - ancestorTag,
467 - // If we're warning about an invalid (non-parent) ancestry, add '...'
468 - isParent ? [] : ['...'],
469 - childOwnerNames,
470 - childTag,
471 - )
472 - .join(' > ');
473 -
474 - return ownerInfo;
475 - };
476 -
407 var didWarn = {};
408
479 - validateDOMNesting = function(
480 - childTag,
481 - childText,
482 - childInstance,
483 - ancestorInfo,
484 - ) {
409 + validateDOMNesting = function(childTag, childText, ancestorInfo) {
410 ancestorInfo = ancestorInfo || emptyAncestorInfo;
411 var parentInfo = ancestorInfo.current;
412 var parentTag = parentInfo && parentInfo.tag;
@@ -505,24 +430,8 @@ if (__DEV__) {
430 return;
431 }
432
508 - var ancestorInstance = invalidParentOrAncestor.instance;
433 var ancestorTag = invalidParentOrAncestor.tag;
510 - var addendum;
511 -
512 - if (childInstance != null) {
513 - addendum =
514 - ' See ' +
515 - getOwnerInfo(
516 - childInstance,
517 - childTag,
518 - ancestorInstance,
519 - ancestorTag,
520 - !!invalidParent,
521 - ) +
522 - '.';
523 - } else {
524 - addendum = getCurrentFiberStackAddendum();
525 - }
434 + var addendum = getCurrentFiberStackAddendum();
435
436 var warnKey =
437 !!invalidParent + '|' + childTag + '|' + ancestorTag + '|' + addendum;
src/renderers/dom/shared/warnValidStyle.js
+20 -31
@@ -15,7 +15,6 @@ var warnValidStyle = emptyFunction;
15
16 if (__DEV__) {
17 var camelizeStyleName = require('fbjs/lib/camelizeStyleName');
18 - var getComponentName = require('getComponentName');
18 var warning = require('fbjs/lib/warning');
19 var {getCurrentFiberOwnerName} = require('ReactDebugCurrentFiber');
20
@@ -30,7 +29,7 @@ if (__DEV__) {
29 var warnedForNaNValue = false;
30 var warnedForInfinityValue = false;
31
33 - var warnHyphenatedStyleName = function(name, owner) {
32 + var warnHyphenatedStyleName = function(name) {
33 if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
34 return;
35 }
@@ -41,11 +40,11 @@ if (__DEV__) {
40 'Unsupported style property %s. Did you mean %s?%s',
41 name,
42 camelizeStyleName(name),
44 - checkRenderMessage(owner),
43 + checkRenderMessage(),
44 );
45 };
46
48 - var warnBadVendoredStyleName = function(name, owner) {
47 + var warnBadVendoredStyleName = function(name) {
48 if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
49 return;
50 }
@@ -56,11 +55,11 @@ if (__DEV__) {
55 'Unsupported vendor-prefixed style property %s. Did you mean %s?%s',
56 name,
57 name.charAt(0).toUpperCase() + name.slice(1),
59 - checkRenderMessage(owner),
58 + checkRenderMessage(),
59 );
60 };
61
63 - var warnStyleValueWithSemicolon = function(name, value, owner) {
62 + var warnStyleValueWithSemicolon = function(name, value) {
63 if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
64 return;
65 }
@@ -70,13 +69,13 @@ if (__DEV__) {
69 false,
70 "Style property values shouldn't contain a semicolon.%s " +
71 'Try "%s: %s" instead.',
73 - checkRenderMessage(owner),
72 + checkRenderMessage(),
73 name,
74 value.replace(badStyleValueWithSemicolonPattern, ''),
75 );
76 };
77
79 - var warnStyleValueIsNaN = function(name, value, owner) {
78 + var warnStyleValueIsNaN = function(name, value) {
79 if (warnedForNaNValue) {
80 return;
81 }
@@ -86,11 +85,11 @@ if (__DEV__) {
85 false,
86 '`NaN` is an invalid value for the `%s` css style property.%s',
87 name,
89 - checkRenderMessage(owner),
88 + checkRenderMessage(),
89 );
90 };
91
93 - var warnStyleValueIsInfinity = function(name, value, owner) {
92 + var warnStyleValueIsInfinity = function(name, value) {
93 if (warnedForInfinityValue) {
94 return;
95 }
@@ -100,21 +99,16 @@ if (__DEV__) {
99 false,
100 '`Infinity` is an invalid value for the `%s` css style property.%s',
101 name,
103 - checkRenderMessage(owner),
102 + checkRenderMessage(),
103 );
104 };
105
107 - var checkRenderMessage = function(owner) {
106 + var checkRenderMessage = function() {
107 var ownerName;
109 - if (owner != null) {
110 - // Stack passes the owner manually all the way to CSSPropertyOperations.
111 - ownerName = getComponentName(owner);
112 - } else {
113 - // Fiber doesn't pass it but uses ReactDebugCurrentFiber to track it.
114 - // It is only enabled in development and tracks host components too.
115 - ownerName = getCurrentFiberOwnerName();
116 - // TODO: also report the stack.
117 - }
108 + // Fiber doesn't pass it but uses ReactDebugCurrentFiber to track it.
109 + // It is only enabled in development and tracks host components too.
110 + ownerName = getCurrentFiberOwnerName();
111 + // TODO: also report the stack.
112 if (ownerName) {
113 return '\n\nCheck the render method of `' + ownerName + '`.';
114 }
@@ -122,24 +116,19 @@ if (__DEV__) {
116 };
117
118 warnValidStyle = function(name, value, component) {
125 - var owner;
126 - if (component) {
127 - // TODO: this only works with Stack. Seems like we need to add unit tests?
128 - owner = component._currentElement._owner;
129 - }
119 if (name.indexOf('-') > -1) {
131 - warnHyphenatedStyleName(name, owner);
120 + warnHyphenatedStyleName(name);
121 } else if (badVendoredStyleNamePattern.test(name)) {
133 - warnBadVendoredStyleName(name, owner);
122 + warnBadVendoredStyleName(name);
123 } else if (badStyleValueWithSemicolonPattern.test(value)) {
135 - warnStyleValueWithSemicolon(name, value, owner);
124 + warnStyleValueWithSemicolon(name, value);
125 }
126
127 if (typeof value === 'number') {
128 if (isNaN(value)) {
140 - warnStyleValueIsNaN(name, value, owner);
129 + warnStyleValueIsNaN(name, value);
130 } else if (!isFinite(value)) {
142 - warnStyleValueIsInfinity(name, value, owner);
131 + warnStyleValueIsInfinity(name, value);
132 }
133 }
134 };
src/renderers/dom/test/ReactTestUtilsEntry.js
+2 -38
@@ -43,35 +43,6 @@ function Event(suffix) {}
43 * @class ReactTestUtils
44 */
45
46 -function findAllInRenderedStackTreeInternal(inst, test) {
47 - if (!inst || !inst.getPublicInstance) {
48 - return [];
49 - }
50 - var publicInst = inst.getPublicInstance();
51 - var ret = test(publicInst) ? [publicInst] : [];
52 - var currentElement = inst._currentElement;
53 - if (ReactTestUtils.isDOMComponent(publicInst)) {
54 - var renderedChildren = inst._renderedChildren;
55 - var key;
56 - for (key in renderedChildren) {
57 - if (!renderedChildren.hasOwnProperty(key)) {
58 - continue;
59 - }
60 - ret = ret.concat(
61 - findAllInRenderedStackTreeInternal(renderedChildren[key], test),
62 - );
63 - }
64 - } else if (
65 - React.isValidElement(currentElement) &&
66 - typeof currentElement.type === 'function'
67 - ) {
68 - ret = ret.concat(
69 - findAllInRenderedStackTreeInternal(inst._renderedComponent, test),
70 - );
71 - }
72 - return ret;
73 -}
74 -
46 function findAllInRenderedFiberTreeInternal(fiber, test) {
47 if (!fiber) {
48 return [];
@@ -169,10 +140,7 @@ var ReactTestUtils = {
140 return false;
141 }
142 var internalInstance = ReactInstanceMap.get(inst);
172 - var constructor = typeof internalInstance.tag === 'number'
173 - ? internalInstance.type // Fiber reconciler
174 - : internalInstance._currentElement.type; // Stack reconciler
175 -
143 + var constructor = internalInstance.type;
144 return constructor === type;
145 },
146
@@ -185,11 +153,7 @@ var ReactTestUtils = {
153 'findAllInRenderedTree(...): instance must be a composite component',
154 );
155 var internalInstance = ReactInstanceMap.get(inst);
188 - if (internalInstance && typeof internalInstance.tag === 'number') {
189 - return findAllInRenderedFiberTreeInternal(internalInstance, test);
190 - } else {
191 - return findAllInRenderedStackTreeInternal(internalInstance, test);
192 - }
156 + return findAllInRenderedFiberTreeInternal(internalInstance, test);
157 },
158
159 /**
src/renderers/native/ReactNativeComponentTree.js
-33
@@ -14,41 +14,10 @@ var invariant = require('fbjs/lib/invariant');
14 var instanceCache = {};
15 var instanceProps = {};
16
17 -/**
18 - * Drill down (through composites and empty components) until we get a host or
19 - * host text component.
20 - *
21 - * This is pretty polymorphic but unavoidable with the current structure we have
22 - * for `_renderedChildren`.
23 - */
24 -function getRenderedHostOrTextFromComponent(component) {
25 - var rendered;
26 - while ((rendered = component._renderedComponent)) {
27 - component = rendered;
28 - }
29 - return component;
30 -}
31 -
32 -/**
33 - * Populate `_hostNode` on the rendered host/text component with the given
34 - * DOM node. The passed `inst` can be a composite.
35 - */
36 -function precacheNode(inst, tag) {
37 - var nativeInst = getRenderedHostOrTextFromComponent(inst);
38 - instanceCache[tag] = nativeInst;
39 -}
40 -
17 function precacheFiberNode(hostInst, tag) {
18 instanceCache[tag] = hostInst;
19 }
20
45 -function uncacheNode(inst) {
46 - var tag = inst._rootNodeID;
47 - if (tag) {
48 - delete instanceCache[tag];
49 - }
50 -}
51 -
21 function uncacheFiberNode(tag) {
22 delete instanceCache[tag];
23 delete instanceProps[tag];
@@ -77,9 +46,7 @@ var ReactNativeComponentTree = {
46 getInstanceFromNode: getInstanceFromTag,
47 getNodeFromInstance: getTagFromInstance,
48 precacheFiberNode,
80 - precacheNode,
49 uncacheFiberNode,
82 - uncacheNode,
50 getFiberCurrentPropsFromNode,
51 updateFiberProps,
52 };
src/renderers/native/__tests__/ReactNativeEvents-test.js
+2 -6
@@ -250,9 +250,7 @@ it('handles when a responder is unmounted while a touch sequence is in progress'
250 if (responder === null) {
251 return null;
252 }
253 - const props = typeof responder.tag === 'number'
254 - ? responder.memoizedProps
255 - : responder._currentElement.props;
253 + const props = responder.memoizedProps;
254 return props ? props.id : null;
255 }
256
@@ -342,9 +340,7 @@ it('handles events without target', () => {
340 if (responder === null) {
341 return null;
342 }
345 - const props = typeof responder.tag === 'number'
346 - ? responder.memoizedProps
347 - : responder._currentElement.props;
343 + const props = responder.memoizedProps;
344 return props ? props.id : null;
345 }
346
src/renderers/shared/fiber/ReactChildFiber.js
+7 -13
@@ -13,7 +13,6 @@
13 import type {ReactElement} from 'ReactElementType';
14 import type {ReactCoroutine, ReactPortal, ReactYield} from 'ReactTypes';
15 import type {Fiber} from 'ReactFiber';
16 -import type {ReactInstance} from 'ReactInstanceType';
16 import type {PriorityLevel} from 'ReactPriorityLevel';
17
18 var {REACT_COROUTINE_TYPE, REACT_YIELD_TYPE} = require('ReactCoroutine');
@@ -120,20 +119,15 @@ function coerceRef(current: Fiber | null, element: ReactElement) {
119 let mixedRef = element.ref;
120 if (mixedRef !== null && typeof mixedRef !== 'function') {
121 if (element._owner) {
123 - const owner: ?(Fiber | ReactInstance) = (element._owner: any);
122 + const owner: ?Fiber = (element._owner: any);
123 let inst;
124 if (owner) {
126 - if (typeof owner.tag === 'number') {
127 - const ownerFiber = ((owner: any): Fiber);
128 - invariant(
129 - ownerFiber.tag === ClassComponent,
130 - 'Stateless function components cannot have refs.',
131 - );
132 - inst = ownerFiber.stateNode;
133 - } else {
134 - // Stack
135 - inst = (owner: any).getPublicInstance();
136 - }
125 + const ownerFiber = ((owner: any): Fiber);
126 + invariant(
127 + ownerFiber.tag === ClassComponent,
128 + 'Stateless function components cannot have refs.',
129 + );
130 + inst = ownerFiber.stateNode;
131 }
132 invariant(
133 inst,
src/renderers/shared/fiber/ReactDebugCurrentFiber.js
+3 -2
@@ -29,8 +29,9 @@ function getCurrentFiberOwnerName(): string | null {
29 if (fiber === null) {
30 return null;
31 }
32 - if (fiber._debugOwner != null) {
33 - return getComponentName(fiber._debugOwner);
32 + const owner = fiber._debugOwner;
33 + if (owner !== null && typeof owner !== 'undefined') {
34 + return getComponentName(owner);
35 }
36 }
37 return null;
src/renderers/shared/fiber/ReactFiber.js
+3 -4
@@ -11,7 +11,6 @@
11 'use strict';
12
13 import type {ReactElement, Source} from 'ReactElementType';
14 -import type {ReactInstance, DebugID} from 'ReactInstanceType';
14 import type {
15 ReactCoroutine,
16 ReactFragment,
@@ -147,9 +146,9 @@ export type Fiber = {|
146 // workInProgress : Fiber -> alternate The alternate used for reuse happens
147 // to be the same as work in progress.
148 // __DEV__ only
150 - _debugID?: DebugID,
149 + _debugID?: number,
150 _debugSource?: Source | null,
152 - _debugOwner?: Fiber | ReactInstance | null, // Stack compatible
151 + _debugOwner?: Fiber | null,
152 _debugIsCurrentlyTiming?: boolean,
153 |};
154
@@ -349,7 +348,7 @@ function createFiberFromElementType(
348 type: mixed,
349 key: null | string,
350 internalContextTag: TypeOfInternalContext,
352 - debugOwner: null | Fiber | ReactInstance,
351 + debugOwner: null | Fiber,
352 ): Fiber {
353 let fiber;
354 if (typeof type === 'function') {
src/renderers/shared/fiber/ReactFiberReconciler.js
+11 -4
@@ -25,7 +25,9 @@ var {
25 } = require('ReactFiberContext');
26 var {createFiberRoot} = require('ReactFiberRoot');
27 var ReactFiberScheduler = require('ReactFiberScheduler');
28 +var ReactInstanceMap = require('ReactInstanceMap');
29 var {HostComponent} = require('ReactTypeOfWork');
30 +var emptyObject = require('fbjs/lib/emptyObject');
31
32 if (__DEV__) {
33 var warning = require('fbjs/lib/warning');
@@ -39,8 +41,6 @@ var {
41 findCurrentHostFiberWithNoPortals,
42 } = require('ReactFiberTreeReflection');
43
42 -var getContextForSubtree = require('getContextForSubtree');
43 -
44 export type Deadline = {
45 timeRemaining: () => number,
46 };
@@ -178,12 +178,19 @@ export type Reconciler<C, I, TI> = {
178 findHostInstanceWithNoPortals(component: Fiber): I | TI | null,
179 };
180
181 -getContextForSubtree._injectFiber(function(fiber: Fiber) {
181 +function getContextForSubtree(
182 + parentComponent: ?React$Component<any, any>,
183 +): Object {
184 + if (!parentComponent) {
185 + return emptyObject;
186 + }
187 +
188 + const fiber = ReactInstanceMap.get(parentComponent);
189 const parentContext = findCurrentUnmaskedContext(fiber);
190 return isContextProvider(fiber)
191 ? processChildContext(fiber, parentContext)
192 : parentContext;
186 -});
193 +}
194
195 module.exports = function<T, P, I, TI, PI, C, CX, PL>(
196 config: HostConfig<T, P, I, TI, PI, C, CX, PL>,
src/renderers/shared/hooks/ReactHostOperationHistoryHook.js deleted
-52
@@ -1,52 +0,0 @@
1 -/**
2 - * Copyright (c) 2016-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule ReactHostOperationHistoryHook
8 - * @flow
9 - */
10 -
11 -'use strict';
12 -
13 -import type {DebugID} from 'ReactInstanceType';
14 -
15 -export type Operation = {instanceID: DebugID} & (
16 - | {type: 'mount', payload: string}
17 - | {type: 'insert child', payload: {toIndex: number, content: string}}
18 - | {type: 'move child', payload: {fromIndex: number, toIndex: number}}
19 - | {type: 'replace children', payload: string}
20 - | {type: 'replace text', payload: string}
21 - | {type: 'replace with', payload: string}
22 - | {type: 'update styles', payload: mixed /* Style Object */}
23 - | {type: 'update attribute', payload: {[name: string]: string}}
24 - | {type: 'remove attribute', payload: string});
25 -
26 -// Trust the developer to only use this with a __DEV__ check
27 -var ReactHostOperationHistoryHook = ((null: any): typeof ReactHostOperationHistoryHook);
28 -
29 -if (__DEV__) {
30 - var history: Array<Operation> = [];
31 -
32 - ReactHostOperationHistoryHook = {
33 - onHostOperation(operation: Operation) {
34 - history.push(operation);
35 - },
36 -
37 - clearHistory(): void {
38 - if (ReactHostOperationHistoryHook._preventClearing) {
39 - // Should only be used for tests.
40 - return;
41 - }
42 -
43 - history = [];
44 - },
45 -
46 - getHistory(): Array<Operation> {
47 - return history;
48 - },
49 - };
50 -}
51 -
52 -module.exports = ReactHostOperationHistoryHook;
src/renderers/shared/hooks/ReactInvalidSetStateWarningHook.js deleted
-39
@@ -1,39 +0,0 @@
1 -/**
2 - * Copyright (c) 2016-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule ReactInvalidSetStateWarningHook
8 - * @flow
9 - */
10 -
11 -'use strict';
12 -
13 -var ReactInvalidSetStateWarningHook = {};
14 -
15 -if (__DEV__) {
16 - var warning = require('fbjs/lib/warning');
17 - var processingChildContext = false;
18 -
19 - var warnInvalidSetState = function() {
20 - warning(
21 - !processingChildContext,
22 - 'setState(...): Cannot call setState() inside getChildContext()',
23 - );
24 - };
25 -
26 - ReactInvalidSetStateWarningHook = {
27 - onBeginProcessingChildContext(): void {
28 - processingChildContext = true;
29 - },
30 - onEndProcessingChildContext(): void {
31 - processingChildContext = false;
32 - },
33 - onSetState(): void {
34 - warnInvalidSetState();
35 - },
36 - };
37 -}
38 -
39 -module.exports = ReactInvalidSetStateWarningHook;
src/renderers/shared/shared/ReactTreeTraversal.js
+10 -15
@@ -12,21 +12,16 @@
12 var {HostComponent} = require('ReactTypeOfWork');
13
14 function getParent(inst) {
15 - if (inst._hostParent !== undefined) {
16 - return inst._hostParent;
17 - }
18 - if (typeof inst.tag === 'number') {
19 - do {
20 - inst = inst.return;
21 - // TODO: If this is a HostRoot we might want to bail out.
22 - // That is depending on if we want nested subtrees (layers) to bubble
23 - // events to their parent. We could also go through parentNode on the
24 - // host node but that wouldn't work for React Native and doesn't let us
25 - // do the portal feature.
26 - } while (inst && inst.tag !== HostComponent);
27 - if (inst) {
28 - return inst;
29 - }
15 + do {
16 + inst = inst.return;
17 + // TODO: If this is a HostRoot we might want to bail out.
18 + // That is depending on if we want nested subtrees (layers) to bubble
19 + // events to their parent. We could also go through parentNode on the
20 + // host node but that wouldn't work for React Native and doesn't let us
21 + // do the portal feature.
22 + } while (inst && inst.tag !== HostComponent);
23 + if (inst) {
24 + return inst;
25 }
26 return null;
27 }
src/renderers/shared/shared/event/EventPluginHub.js
+13 -36
@@ -122,43 +122,20 @@ var EventPluginHub = {
122
123 // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
124 // live here; needs to be moved to a better place soon
125 - if (typeof inst.tag === 'number') {
126 - const stateNode = inst.stateNode;
127 - if (!stateNode) {
128 - // Work in progress (ex: onload events in incremental mode).
129 - return null;
130 - }
131 - const props = EventPluginUtils.getFiberCurrentPropsFromNode(stateNode);
132 - if (!props) {
133 - // Work in progress.
134 - return null;
135 - }
136 - listener = props[registrationName];
137 - if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
138 - return null;
139 - }
140 - } else {
141 - const currentElement = inst._currentElement;
142 - if (
143 - typeof currentElement === 'string' ||
144 - typeof currentElement === 'number'
145 - ) {
146 - // Text node, let it bubble through.
147 - return null;
148 - }
149 - if (!inst._rootNodeID) {
150 - // If the instance is already unmounted, we have no listeners.
151 - return null;
152 - }
153 - const props = currentElement.props;
154 - listener = props[registrationName];
155 - if (
156 - shouldPreventMouseEvent(registrationName, currentElement.type, props)
157 - ) {
158 - return null;
159 - }
125 + const stateNode = inst.stateNode;
126 + if (!stateNode) {
127 + // Work in progress (ex: onload events in incremental mode).
128 + return null;
129 + }
130 + const props = EventPluginUtils.getFiberCurrentPropsFromNode(stateNode);
131 + if (!props) {
132 + // Work in progress.
133 + return null;
134 + }
135 + listener = props[registrationName];
136 + if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
137 + return null;
138 }
161 -
139 invariant(
140 !listener || typeof listener === 'function',
141 'Expected `%s` listener to be a function, instead got a value of `%s` type.',
src/renderers/shared/shared/event/PluginModuleType.js
+2 -2
@@ -10,7 +10,7 @@
10
11 'use strict';
12
13 -import type {ReactInstance} from 'ReactInstanceType';
13 +import type {Fiber} from 'ReactFiber';
14 import type {
15 DispatchConfig,
16 ReactSyntheticEvent,
@@ -26,7 +26,7 @@ export type PluginModule<NativeEvent> = {
26 eventTypes: EventTypes,
27 extractEvents: (
28 topLevelType: string,
29 - targetInst: ReactInstance,
29 + targetInst: Fiber,
30 nativeTarget: NativeEvent,
31 nativeEventTarget: EventTarget,
32 ) => null | ReactSyntheticEvent,
src/renderers/shared/shared/event/ReactControlledComponent.js
+12 -22
@@ -36,30 +36,20 @@ function restoreStateOfTarget(target) {
36 // Unmounted
37 return;
38 }
39 - if (typeof internalInstance.tag === 'number') {
40 - invariant(
41 - fiberHostComponent &&
42 - typeof fiberHostComponent.restoreControlledState === 'function',
43 - 'Fiber needs to be injected to handle a fiber target for controlled ' +
44 - 'events. This error is likely caused by a bug in React. Please file an issue.',
45 - );
46 - const props = EventPluginUtils.getFiberCurrentPropsFromNode(
47 - internalInstance.stateNode,
48 - );
49 - fiberHostComponent.restoreControlledState(
50 - internalInstance.stateNode,
51 - internalInstance.type,
52 - props,
53 - );
54 - return;
55 - }
39 invariant(
57 - typeof internalInstance.restoreControlledState === 'function',
58 - 'The internal instance must be a React host component. ' +
59 - 'This error is likely caused by a bug in React. Please file an issue.',
40 + fiberHostComponent &&
41 + typeof fiberHostComponent.restoreControlledState === 'function',
42 + 'Fiber needs to be injected to handle a fiber target for controlled ' +
43 + 'events. This error is likely caused by a bug in React. Please file an issue.',
44 + );
45 + const props = EventPluginUtils.getFiberCurrentPropsFromNode(
46 + internalInstance.stateNode,
47 + );
48 + fiberHostComponent.restoreControlledState(
49 + internalInstance.stateNode,
50 + internalInstance.type,
51 + props,
52 );
61 - // If it is not a Fiber, we can just use dynamic dispatch.
62 - internalInstance.restoreControlledState();
53 }
54
55 var ReactControlledComponent = {
src/renderers/shared/shared/event/ReactGenericBatching.js
+3 -14
@@ -11,30 +11,22 @@
11
12 var ReactControlledComponent = require('ReactControlledComponent');
13
14 -// Used as a way to call batchedUpdates when we don't know if we're in a Fiber
15 -// or Stack context. Such as when we're dispatching events or if third party
14 +// Used as a way to call batchedUpdates when we don't have a reference to
15 +// the renderer. Such as when we're dispatching events or if third party
16 // libraries need to call batchedUpdates. Eventually, this API will go away when
17 // everything is batched by default. We'll then have a similar API to opt-out of
18 // scheduled work and instead do synchronous work.
19
20 // Defaults
21 -var stackBatchedUpdates = function(fn, a, b, c, d, e) {
22 - return fn(a, b, c, d, e);
23 -};
21 var fiberBatchedUpdates = function(fn, bookkeeping) {
22 return fn(bookkeeping);
23 };
24
28 -function performFiberBatchedUpdates(fn, bookkeeping) {
25 +function batchedUpdates(fn, bookkeeping) {
26 // If we have Fiber loaded, we need to wrap this in a batching call so that
27 // Fiber can apply its default priority for this call.
28 return fiberBatchedUpdates(fn, bookkeeping);
29 }
33 -function batchedUpdates(fn, bookkeeping) {
34 - // We first perform work with the stack batching strategy, by passing our
35 - // indirection to it.
36 - return stackBatchedUpdates(performFiberBatchedUpdates, fn, bookkeeping);
37 -}
30
31 var isNestingBatched = false;
32 function batchedUpdatesWithControlledComponents(fn, bookkeeping) {
@@ -58,9 +50,6 @@ function batchedUpdatesWithControlledComponents(fn, bookkeeping) {
50 }
51
52 var ReactGenericBatchingInjection = {
61 - injectStackBatchedUpdates: function(_batchedUpdates) {
62 - stackBatchedUpdates = _batchedUpdates;
63 - },
53 injectFiberBatchedUpdates: function(_batchedUpdates) {
54 fiberBatchedUpdates = _batchedUpdates;
55 },
src/renderers/shared/shared/event/ReactSyntheticEventType.js
+2 -2
@@ -12,7 +12,7 @@
12
13 'use strict';
14
15 -import type {ReactInstance} from 'ReactInstanceType';
15 +import type {Fiber} from 'ReactFiber';
16
17 export type DispatchConfig = {
18 dependencies: Array<string>,
@@ -27,7 +27,7 @@ export type ReactSyntheticEvent = {
27 dispatchConfig: DispatchConfig,
28 getPooled: (
29 dispatchConfig: DispatchConfig,
30 - targetInst: ReactInstance,
30 + targetInst: Fiber,
31 nativeTarget: Event,
32 nativeEventTarget: EventTarget,
33 ) => ReactSyntheticEvent,
src/renderers/shared/shared/event/eventPlugins/__tests__/ResponderEventPlugin-test.js
+35 -26
@@ -9,6 +9,8 @@
9
10 'use strict';
11
12 +var {HostComponent} = require('ReactTypeOfWork');
13 +
14 var EventPluginHub;
15 var ResponderEventPlugin;
16
@@ -318,35 +320,37 @@ var PARENT_HOST_NODE = {};
320 var CHILD_HOST_NODE = {};
321 var CHILD_HOST_NODE2 = {};
322
323 +// These intentionally look like Fibers. ReactTreeTraversal depends on their field names.
324 +// TODO: we could test this with regular DOM nodes (and real fibers) instead.
325 var GRANDPARENT_INST = {
322 - _hostParent: null,
323 - _rootNodeID: '1',
324 - _hostNode: GRANDPARENT_HOST_NODE,
325 - _currentElement: {props: {}},
326 + return: null,
327 + tag: HostComponent,
328 + stateNode: GRANDPARENT_HOST_NODE,
329 + memoizedProps: {},
330 };
331 var PARENT_INST = {
328 - _hostParent: GRANDPARENT_INST,
329 - _rootNodeID: '2',
330 - _hostNode: PARENT_HOST_NODE,
331 - _currentElement: {props: {}},
332 + return: GRANDPARENT_INST,
333 + tag: HostComponent,
334 + stateNode: PARENT_HOST_NODE,
335 + memoizedProps: {},
336 };
337 var CHILD_INST = {
334 - _hostParent: PARENT_INST,
335 - _rootNodeID: '3',
336 - _hostNode: CHILD_HOST_NODE,
337 - _currentElement: {props: {}},
338 + return: PARENT_INST,
339 + tag: HostComponent,
340 + stateNode: CHILD_HOST_NODE,
341 + memoizedProps: {},
342 };
343 var CHILD_INST2 = {
340 - _hostParent: PARENT_INST,
341 - _rootNodeID: '4',
342 - _hostNode: CHILD_HOST_NODE2,
343 - _currentElement: {props: {}},
344 + return: PARENT_INST,
345 + tag: HostComponent,
346 + stateNode: CHILD_HOST_NODE2,
347 + memoizedProps: {},
348 };
349
346 -GRANDPARENT_HOST_NODE._reactInstance = GRANDPARENT_INST;
347 -PARENT_HOST_NODE._reactInstance = PARENT_INST;
348 -CHILD_HOST_NODE._reactInstance = CHILD_INST;
349 -CHILD_HOST_NODE2._reactInstance = CHILD_INST2;
350 +GRANDPARENT_HOST_NODE.testInstance = GRANDPARENT_INST;
351 +PARENT_HOST_NODE.testInstance = PARENT_INST;
352 +CHILD_HOST_NODE.testInstance = CHILD_INST;
353 +CHILD_HOST_NODE2.testInstance = CHILD_INST2;
354
355 var three = {
356 grandParent: GRANDPARENT_HOST_NODE,
@@ -361,19 +365,23 @@ var siblings = {
365 };
366
367 function getInstanceFromNode(node) {
364 - return node._reactInstance;
368 + return node.testInstance;
369 }
370
371 function getNodeFromInstance(inst) {
368 - return inst._hostNode;
372 + return inst.stateNode;
373 +}
374 +
375 +function getFiberCurrentPropsFromNode(node) {
376 + return node.testInstance.memoizedProps;
377 }
378
371 -function putListener(node, registrationName, handler) {
372 - node._currentElement.props[registrationName] = handler;
379 +function putListener(instance, registrationName, handler) {
380 + instance.memoizedProps[registrationName] = handler;
381 }
382
375 -function deleteAllListeners(node) {
376 - node._currentElement.props = {};
383 +function deleteAllListeners(instance) {
384 + instance.memoizedProps = {};
385 }
386
387 describe('ResponderEventPlugin', () => {
@@ -398,6 +406,7 @@ describe('ResponderEventPlugin', () => {
406 injectComponentTree({
407 getInstanceFromNode,
408 getNodeFromInstance,
409 + getFiberCurrentPropsFromNode,
410 });
411 });
412
src/renderers/shared/shared/getContextForSubtree.js deleted
-39
@@ -1,39 +0,0 @@
1 -/**
2 - * Copyright (c) 2013-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule getContextForSubtree
8 - * @flow
9 - */
10 -
11 -const ReactInstanceMap = require('ReactInstanceMap');
12 -
13 -const emptyObject = require('fbjs/lib/emptyObject');
14 -const invariant = require('fbjs/lib/invariant');
15 -
16 -let getContextFiber = function(arg) {
17 - invariant(false, 'Missing injection for fiber getContextForSubtree');
18 -};
19 -
20 -function getContextForSubtree(
21 - parentComponent: ?React$Component<any, any>,
22 -): Object {
23 - if (!parentComponent) {
24 - return emptyObject;
25 - }
26 -
27 - const instance = ReactInstanceMap.get(parentComponent);
28 - if (typeof instance.tag === 'number') {
29 - return getContextFiber(instance);
30 - } else {
31 - return instance._processChildContext(instance._context);
32 - }
33 -}
34 -
35 -getContextForSubtree._injectFiber = function(fn) {
36 - getContextFiber = fn;
37 -};
38 -
39 -module.exports = getContextForSubtree;
src/shared/ReactInstanceType.js deleted
-27
@@ -1,27 +0,0 @@
1 -/**
2 - * Copyright (c) 2016-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @providesModule ReactInstanceType
8 - * @flow
9 - */
10 -
11 -'use strict';
12 -
13 -// TODO: delete this file.
14 -// It was only necessary for Stack.
15 -
16 -import type {ReactElement} from 'ReactElementType';
17 -
18 -export type DebugID = number;
19 -
20 -export type ReactInstance = {
21 - mountComponent: any,
22 - unmountComponent: any,
23 - receiveComponent: any,
24 - getName: () => string,
25 - getPublicInstance: any,
26 - _currentElement: ReactElement,
27 -};
src/shared/utils/getComponentName.js
+6 -18
@@ -10,27 +10,15 @@
10
11 'use strict';
12
13 -import type {ReactInstance} from 'ReactInstanceType';
13 import type {Fiber} from 'ReactFiber';
14
16 -function getComponentName(
17 - instanceOrFiber: ReactInstance | Fiber,
18 -): string | null {
19 - if (typeof instanceOrFiber.getName === 'function') {
20 - // Stack reconciler
21 - const instance = ((instanceOrFiber: any): ReactInstance);
22 - return instance.getName();
15 +function getComponentName(fiber: Fiber): string | null {
16 + const {type} = fiber;
17 + if (typeof type === 'string') {
18 + return type;
19 }
24 - if (typeof instanceOrFiber.tag === 'number') {
25 - // Fiber reconciler
26 - const fiber = ((instanceOrFiber: any): Fiber);
27 - const {type} = fiber;
28 - if (typeof type === 'string') {
29 - return type;
30 - }
31 - if (typeof type === 'function') {
32 - return type.displayName || type.name;
33 - }
20 + if (typeof type === 'function') {
21 + return type.displayName || type.name;
22 }
23 return null;
24 }