GeezerVison is showing github.com — [Native] Enable and remove targetAsInstance feature flag. (#18182) · react/react@26aa198
File treeExpand file treeCollapse file tree Open diff view settings react-native-renderer/src
rollup/shims/react-native
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricComponentTree.js +6-14Lines changed: 6 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 | import invariant from 'shared/invariant'; | 9 | 9 |
| 10 | | -import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags'; | 11 | | - | 12 | 10 | function getInstanceFromInstance(instanceHandle) { | 13 | 11 | return instanceHandle; | 14 | 12 | } | 15 | 13 |
| 16 | 14 | function getTagFromInstance(inst) { | 17 | | - if (enableNativeTargetAsInstance) { | 18 | | - let nativeInstance = inst.stateNode.canonical; | 19 | | - invariant( | 20 | | - nativeInstance._nativeTag, | 21 | | - 'All native instances should have a tag.', | 22 | | - ); | 23 | | - return nativeInstance; | 24 | | - } else { | 25 | | - let tag = inst.stateNode.canonical._nativeTag; | 26 | | - invariant(tag, 'All native instances should have a tag.'); | 27 | | - return tag; | 28 | | - } | | 15 | + let nativeInstance = inst.stateNode.canonical; | | 16 | + invariant( | | 17 | + nativeInstance._nativeTag, | | 18 | + 'All native instances should have a tag.', | | 19 | + ); | | 20 | + return nativeInstance; | 29 | 21 | } | 30 | 22 |
| 31 | 23 | export { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricEventEmitter.js +5-10Lines changed: 5 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,6 @@ import {registrationNameModules} from 'legacy-events/EventPluginRegistry'; | 19 | 19 | import {batchedUpdates} from 'legacy-events/ReactGenericBatching'; | 20 | 20 | import accumulateInto from 'legacy-events/accumulateInto'; | 21 | 21 |
| 22 | | -import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags'; | 23 | 22 | import {plugins} from 'legacy-events/EventPluginRegistry'; | 24 | 23 | import getListener from 'legacy-events/getListener'; | 25 | 24 | import {runEventsInBatch} from 'legacy-events/EventBatching'; | @@ -85,16 +84,12 @@ export function dispatchEvent( | 85 | 84 | const targetFiber = (target: null | Fiber); | 86 | 85 |
| 87 | 86 | let eventTarget = null; | 88 | | - if (enableNativeTargetAsInstance) { | 89 | | - if (targetFiber != null) { | 90 | | - const stateNode = targetFiber.stateNode; | 91 | | - // Guard against Fiber being unmounted | 92 | | - if (stateNode != null) { | 93 | | - eventTarget = stateNode.canonical; | 94 | | - } | | 87 | + if (targetFiber != null) { | | 88 | + const stateNode = targetFiber.stateNode; | | 89 | + // Guard against Fiber being unmounted | | 90 | + if (stateNode != null) { | | 91 | + eventTarget = stateNode.canonical; | 95 | 92 | } | 96 | | - } else { | 97 | | - eventTarget = nativeEvent.target; | 98 | 93 | } | 99 | 94 |
| 100 | 95 | batchedUpdates(function() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeComponentTree.js +7-18Lines changed: 7 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 | import invariant from 'shared/invariant'; | 9 | 9 |
| 10 | | -import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags'; | 11 | | - | 12 | 10 | const instanceCache = new Map(); | 13 | 11 | const instanceProps = new Map(); | 14 | 12 |
| @@ -26,23 +24,14 @@ function getInstanceFromTag(tag) { | 26 | 24 | } | 27 | 25 |
| 28 | 26 | function getTagFromInstance(inst) { | 29 | | - if (enableNativeTargetAsInstance) { | 30 | | - let nativeInstance = inst.stateNode; | 31 | | - let tag = nativeInstance._nativeTag; | 32 | | - if (tag === undefined) { | 33 | | - nativeInstance = nativeInstance.canonical; | 34 | | - tag = nativeInstance._nativeTag; | 35 | | - } | 36 | | - invariant(tag, 'All native instances should have a tag.'); | 37 | | - return nativeInstance; | 38 | | - } else { | 39 | | - let tag = inst.stateNode._nativeTag; | 40 | | - if (tag === undefined) { | 41 | | - tag = inst.stateNode.canonical._nativeTag; | 42 | | - } | 43 | | - invariant(tag, 'All native instances should have a tag.'); | 44 | | - return tag; | | 27 | + let nativeInstance = inst.stateNode; | | 28 | + let tag = nativeInstance._nativeTag; | | 29 | + if (tag === undefined) { | | 30 | + nativeInstance = nativeInstance.canonical; | | 31 | + tag = nativeInstance._nativeTag; | 45 | 32 | } | | 33 | + invariant(tag, 'All native instances should have a tag.'); | | 34 | + return nativeInstance; | 46 | 35 | } | 47 | 36 |
| 48 | 37 | export { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeEventEmitter.js +2-7Lines changed: 2 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,6 @@ import {PLUGIN_EVENT_SYSTEM} from 'legacy-events/EventSystemFlags'; | 18 | 18 | import {registrationNameModules} from 'legacy-events/EventPluginRegistry'; | 19 | 19 | import {batchedUpdates} from 'legacy-events/ReactGenericBatching'; | 20 | 20 | import {runEventsInBatch} from 'legacy-events/EventBatching'; | 21 | | -import {enableNativeTargetAsInstance} from 'shared/ReactFeatureFlags'; | 22 | 21 | import {plugins} from 'legacy-events/EventPluginRegistry'; | 23 | 22 | import getListener from 'legacy-events/getListener'; | 24 | 23 | import accumulateInto from 'legacy-events/accumulateInto'; | @@ -104,12 +103,8 @@ function _receiveRootNodeIDEvent( | 104 | 103 | const inst = getInstanceFromNode(rootNodeID); | 105 | 104 |
| 106 | 105 | let target = null; | 107 | | - if (enableNativeTargetAsInstance) { | 108 | | - if (inst != null) { | 109 | | - target = inst.stateNode; | 110 | | - } | 111 | | - } else { | 112 | | - target = nativeEvent.target; | | 106 | + if (inst != null) { | | 107 | + target = inst.stateNode; | 113 | 108 | } | 114 | 109 |
| 115 | 110 | batchedUpdates(function() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js -107Lines changed: 0 additions & 107 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 |
| 13 | 13 | let React; | 14 | 14 | let ReactFabric; | 15 | | -let ReactFeatureFlags; | 16 | 15 | let createReactNativeComponentClass; | 17 | 16 | let UIManager; | 18 | 17 | let StrictMode; | @@ -38,7 +37,6 @@ describe('ReactFabric', () => { | 38 | 37 | React = require('react'); | 39 | 38 | StrictMode = React.StrictMode; | 40 | 39 | ReactFabric = require('react-native-renderer/fabric'); | 41 | | - ReactFeatureFlags = require('shared/ReactFeatureFlags'); | 42 | 40 | UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') | 43 | 41 | .UIManager; | 44 | 42 | createReactNativeComponentClass = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') | @@ -649,112 +647,7 @@ describe('ReactFabric', () => { | 649 | 647 | expect(touchStart2).toBeCalled(); | 650 | 648 | }); | 651 | 649 |
| 652 | | - it('dispatches event with target as reactTag', () => { | 653 | | - ReactFeatureFlags.enableNativeTargetAsInstance = false; | 654 | | - | 655 | | - const View = createReactNativeComponentClass('RCTView', () => ({ | 656 | | - validAttributes: { | 657 | | - id: true, | 658 | | - }, | 659 | | - uiViewClassName: 'RCTView', | 660 | | - directEventTypes: { | 661 | | - topTouchStart: { | 662 | | - registrationName: 'onTouchStart', | 663 | | - }, | 664 | | - topTouchEnd: { | 665 | | - registrationName: 'onTouchEnd', | 666 | | - }, | 667 | | - }, | 668 | | - })); | 669 | | - | 670 | | - function getViewById(id) { | 671 | | - const [ | 672 | | - reactTag, | 673 | | - , | 674 | | - , | 675 | | - , | 676 | | - instanceHandle, | 677 | | - ] = nativeFabricUIManager.createNode.mock.calls.find( | 678 | | - args => args[3] && args[3].id === id, | 679 | | - ); | 680 | | - | 681 | | - return {reactTag, instanceHandle}; | 682 | | - } | 683 | | - | 684 | | - const ref1 = React.createRef(); | 685 | | - const ref2 = React.createRef(); | 686 | | - | 687 | | - ReactFabric.render( | 688 | | - <View id="parent"> | 689 | | - <View | 690 | | - ref={ref1} | 691 | | - id="one" | 692 | | - onResponderStart={event => { | 693 | | - expect(ref1.current).not.toBeNull(); | 694 | | - expect(ReactFabric.findNodeHandle(ref1.current)).toEqual( | 695 | | - event.target, | 696 | | - ); | 697 | | - expect(ReactFabric.findNodeHandle(ref1.current)).toEqual( | 698 | | - event.currentTarget, | 699 | | - ); | 700 | | - }} | 701 | | - onStartShouldSetResponder={() => true} | 702 | | - /> | 703 | | - <View | 704 | | - ref={ref2} | 705 | | - id="two" | 706 | | - onResponderStart={event => { | 707 | | - expect(ref2.current).not.toBeNull(); | 708 | | - expect(ReactFabric.findNodeHandle(ref2.current)).toEqual( | 709 | | - event.target, | 710 | | - ); | 711 | | - expect(ReactFabric.findNodeHandle(ref2.current)).toEqual( | 712 | | - event.currentTarget, | 713 | | - ); | 714 | | - }} | 715 | | - onStartShouldSetResponder={() => true} | 716 | | - /> | 717 | | - </View>, | 718 | | - 1, | 719 | | - ); | 720 | | - | 721 | | - let [ | 722 | | - dispatchEvent, | 723 | | - ] = nativeFabricUIManager.registerEventHandler.mock.calls[0]; | 724 | | - | 725 | | - dispatchEvent(getViewById('one').instanceHandle, 'topTouchStart', { | 726 | | - target: getViewById('one').reactTag, | 727 | | - identifier: 17, | 728 | | - touches: [], | 729 | | - changedTouches: [], | 730 | | - }); | 731 | | - dispatchEvent(getViewById('one').instanceHandle, 'topTouchEnd', { | 732 | | - target: getViewById('one').reactTag, | 733 | | - identifier: 17, | 734 | | - touches: [], | 735 | | - changedTouches: [], | 736 | | - }); | 737 | | - | 738 | | - dispatchEvent(getViewById('two').instanceHandle, 'topTouchStart', { | 739 | | - target: getViewById('two').reactTag, | 740 | | - identifier: 17, | 741 | | - touches: [], | 742 | | - changedTouches: [], | 743 | | - }); | 744 | | - | 745 | | - dispatchEvent(getViewById('two').instanceHandle, 'topTouchEnd', { | 746 | | - target: getViewById('two').reactTag, | 747 | | - identifier: 17, | 748 | | - touches: [], | 749 | | - changedTouches: [], | 750 | | - }); | 751 | | - | 752 | | - expect.assertions(6); | 753 | | - }); | 754 | | - | 755 | 650 | it('dispatches event with target as instance', () => { | 756 | | - ReactFeatureFlags.enableNativeTargetAsInstance = true; | 757 | | - | 758 | 651 | const View = createReactNativeComponentClass('RCTView', () => ({ | 759 | 652 | validAttributes: { | 760 | 653 | id: true, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js -79Lines changed: 0 additions & 79 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,6 @@ let PropTypes; | 14 | 14 | let RCTEventEmitter; | 15 | 15 | let React; | 16 | 16 | let ReactNative; | 17 | | -let ReactFeatureFlags; | 18 | 17 | let ResponderEventPlugin; | 19 | 18 | let UIManager; | 20 | 19 | let createReactNativeComponentClass; | @@ -69,7 +68,6 @@ beforeEach(() => { | 69 | 68 | .RCTEventEmitter; | 70 | 69 | React = require('react'); | 71 | 70 | ReactNative = require('react-native-renderer'); | 72 | | - ReactFeatureFlags = require('shared/ReactFeatureFlags'); | 73 | 71 | ResponderEventPlugin = require('legacy-events/ResponderEventPlugin').default; | 74 | 72 | UIManager = require('react-native/Libraries/ReactPrivate/ReactNativePrivateInterface') | 75 | 73 | .UIManager; | @@ -459,84 +457,7 @@ it('handles events without target', () => { | 459 | 457 | ]); | 460 | 458 | }); | 461 | 459 |
| 462 | | -it('dispatches event with target as reactTag', () => { | 463 | | - ReactFeatureFlags.enableNativeTargetAsInstance = false; | 464 | | - const EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; | 465 | | - | 466 | | - const View = fakeRequireNativeComponent('View', {id: true}); | 467 | | - | 468 | | - function getViewById(id) { | 469 | | - return UIManager.createView.mock.calls.find( | 470 | | - args => args[3] && args[3].id === id, | 471 | | - )[0]; | 472 | | - } | 473 | | - | 474 | | - const ref1 = React.createRef(); | 475 | | - const ref2 = React.createRef(); | 476 | | - | 477 | | - ReactNative.render( | 478 | | - <View id="parent"> | 479 | | - <View | 480 | | - ref={ref1} | 481 | | - id="one" | 482 | | - onResponderStart={event => { | 483 | | - expect(ref1.current).not.toBeNull(); | 484 | | - expect(ReactNative.findNodeHandle(ref1.current)).toEqual( | 485 | | - event.target, | 486 | | - ); | 487 | | - expect(ReactNative.findNodeHandle(ref1.current)).toEqual( | 488 | | - event.currentTarget, | 489 | | - ); | 490 | | - }} | 491 | | - onStartShouldSetResponder={() => true} | 492 | | - /> | 493 | | - <View | 494 | | - ref={ref2} | 495 | | - id="two" | 496 | | - onResponderStart={event => { | 497 | | - expect(ref2.current).not.toBeNull(); | 498 | | - expect(ReactNative.findNodeHandle(ref2.current)).toEqual( | 499 | | - event.target, | 500 | | - ); | 501 | | - expect(ReactNative.findNodeHandle(ref2.current)).toEqual( | 502 | | - event.currentTarget, | 503 | | - ); | 504 | | - }} | 505 | | - onStartShouldSetResponder={() => true} | 506 | | - /> | 507 | | - </View>, | 508 | | - 1, | 509 | | - ); | 510 | | - | 511 | | - EventEmitter.receiveTouches( | 512 | | - 'topTouchStart', | 513 | | - [{target: getViewById('one'), identifier: 17}], | 514 | | - [0], | 515 | | - ); | 516 | | - | 517 | | - EventEmitter.receiveTouches( | 518 | | - 'topTouchEnd', | 519 | | - [{target: getViewById('one'), identifier: 17}], | 520 | | - [0], | 521 | | - ); | 522 | | - | 523 | | - EventEmitter.receiveTouches( | 524 | | - 'topTouchStart', | 525 | | - [{target: getViewById('two'), identifier: 18}], | 526 | | - [0], | 527 | | - ); | 528 | | - | 529 | | - EventEmitter.receiveTouches( | 530 | | - 'topTouchEnd', | 531 | | - [{target: getViewById('two'), identifier: 18}], | 532 | | - [0], | 533 | | - ); | 534 | | - | 535 | | - expect.assertions(6); | 536 | | -}); | 537 | | - | 538 | 460 | it('dispatches event with target as instance', () => { | 539 | | - ReactFeatureFlags.enableNativeTargetAsInstance = true; | 540 | 461 | const EventEmitter = RCTEventEmitter.register.mock.calls[0][0]; | 541 | 462 |
| 542 | 463 | const View = fakeRequireNativeComponent('View', {id: true}); | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/ReactFeatureFlags.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -83,9 +83,6 @@ export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 83 | 83 |
| 84 | 84 | export const enableTrustedTypesIntegration = false; | 85 | 85 |
| 86 | | -// Flag to turn event.target and event.currentTarget in ReactNative from a reactTag to a component instance | 87 | | -export const enableNativeTargetAsInstance = false; | 88 | | - | 89 | 86 | // Controls sequence of passive effect destroy and create functions. | 90 | 87 | // If this flag is off, destroy and create functions may be interleaved. | 91 | 88 | // When the flag is on, all destroy functions will be run (for all fibers) | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.native-fb.js -5Lines changed: 0 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,11 +12,6 @@ import invariant from 'shared/invariant'; | 12 | 12 | import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags'; | 13 | 13 | import typeof * as ExportsType from './ReactFeatureFlags.native-fb'; | 14 | 14 |
| 15 | | -// Uncomment to re-export dynamic flags from the fbsource version. | 16 | | -export const { | 17 | | - enableNativeTargetAsInstance, | 18 | | -} = require('../shims/ReactFeatureFlags'); | 19 | | - | 20 | 15 | // The rest of the flags are static for better dead code elimination. | 21 | 16 | export const enableUserTimingAPI = __DEV__; | 22 | 17 | export const enableProfilerTimer = __PROFILE__; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.native-oss.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false; | 36 | 36 | export const disableLegacyContext = false; | 37 | 37 | export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 38 | 38 | export const enableTrustedTypesIntegration = false; | 39 | | -export const enableNativeTargetAsInstance = false; | 40 | 39 | export const disableTextareaChildren = false; | 41 | 40 | export const disableMapsAsChildren = false; | 42 | 41 | export const warnUnstableRenderSubtreeIntoContainer = false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/forks/ReactFeatureFlags.persistent.js -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,7 +36,6 @@ export const warnAboutStringRefs = false; | 36 | 36 | export const disableLegacyContext = false; | 37 | 37 | export const disableSchedulerTimeoutBasedOnReactExpirationTime = false; | 38 | 38 | export const enableTrustedTypesIntegration = false; | 39 | | -export const enableNativeTargetAsInstance = false; | 40 | 39 | export const disableTextareaChildren = false; | 41 | 40 | export const disableMapsAsChildren = false; | 42 | 41 | export const warnUnstableRenderSubtreeIntoContainer = false; | |
|