Skip to content

Commit

Permalink
Merge pull request #47 from facebook/master
Browse files Browse the repository at this point in the history
Sync Fork from Upstream Repo
  • Loading branch information
sthagen authored Feb 26, 2021
2 parents 3e5228f + 0cf9fc1 commit 6414a56
Show file tree
Hide file tree
Showing 36 changed files with 345 additions and 152 deletions.
3 changes: 1 addition & 2 deletions packages/react-devtools-scheduling-profiler/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ export {
COMFORTABLE_LINE_HEIGHT,
COMPACT_LINE_HEIGHT,
} from 'react-devtools-shared/src/constants.js';
import {TotalLanes} from 'react-reconciler/src/ReactFiberLane.new';

export const REACT_TOTAL_NUM_LANES = TotalLanes;
export const REACT_TOTAL_NUM_LANES = 31;
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ describe('ReactDOMServerPartialHydration', () => {
resolve();
await promise;
Scheduler.unstable_flushAll();
await null;
jest.runAllTimers();

// We should now have hydrated with a ref on the existing span.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ describe('ReactDOMServerHydration', () => {
jest.runAllTimers();
await Promise.resolve();
Scheduler.unstable_flushAll();
await null;
expect(element.textContent).toBe('Hello world');
});

Expand Down
41 changes: 41 additions & 0 deletions packages/react-is/index.experimental.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

export {
isValidElementType,
typeOf,
ContextConsumer,
ContextProvider,
Element,
ForwardRef,
Fragment,
Lazy,
Memo,
Portal,
Profiler,
StrictMode,
Suspense,
unstable_SuspenseList,
isAsyncMode,
isConcurrentMode,
isContextConsumer,
isContextProvider,
isElement,
isForwardRef,
isFragment,
isLazy,
isMemo,
isPortal,
isProfiler,
isStrictMode,
isSuspense,
unstable_isSuspenseList,
} from './src/ReactIs';
39 changes: 39 additions & 0 deletions packages/react-is/index.stable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

export {
isValidElementType,
typeOf,
ContextConsumer,
ContextProvider,
Element,
ForwardRef,
Fragment,
Lazy,
Memo,
Portal,
Profiler,
StrictMode,
Suspense,
isAsyncMode,
isConcurrentMode,
isContextConsumer,
isContextProvider,
isElement,
isForwardRef,
isFragment,
isLazy,
isMemo,
isPortal,
isProfiler,
isStrictMode,
isSuspense,
} from './src/ReactIs';
4 changes: 4 additions & 0 deletions packages/react-is/src/ReactIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const Portal = REACT_PORTAL_TYPE;
export const Profiler = REACT_PROFILER_TYPE;
export const StrictMode = REACT_STRICT_MODE_TYPE;
export const Suspense = REACT_SUSPENSE_TYPE;
export const unstable_SuspenseList = REACT_SUSPENSE_LIST_TYPE;

export {isValidElementType};

Expand Down Expand Up @@ -142,3 +143,6 @@ export function isStrictMode(object: any) {
export function isSuspense(object: any) {
return typeOf(object) === REACT_SUSPENSE_TYPE;
}
export function unstable_isSuspenseList(object: any) {
return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
}
18 changes: 18 additions & 0 deletions packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ describe('ReactIs', () => {
expect(ReactIs.isSuspense(<div />)).toBe(false);
});

// @gate experimental
it('should identify suspense list', () => {
expect(ReactIs.isValidElementType(React.unstable_SuspenseList)).toBe(true);
expect(ReactIs.typeOf(<React.unstable_SuspenseList />)).toBe(
ReactIs.unstable_SuspenseList,
);
expect(
ReactIs.unstable_isSuspenseList(<React.unstable_SuspenseList />),
).toBe(true);
expect(
ReactIs.unstable_isSuspenseList({type: ReactIs.unstable_SuspenseList}),
).toBe(false);
expect(ReactIs.unstable_isSuspenseList('React.unstable_SuspenseList')).toBe(
false,
);
expect(ReactIs.unstable_isSuspenseList(<div />)).toBe(false);
});

it('should identify profile root', () => {
expect(ReactIs.isValidElementType(React.Profiler)).toBe(true);
expect(
Expand Down
19 changes: 12 additions & 7 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type {HostComponent} from './ReactNativeTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef} from 'react';
import type {ElementRef, Element, ElementType} from 'react';

import './ReactFabricInjection';

Expand Down Expand Up @@ -47,8 +47,8 @@ import getComponentName from 'shared/getComponentName';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

function findHostInstance_DEPRECATED(
componentOrHandle: any,
function findHostInstance_DEPRECATED<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
): ?ElementRef<HostComponent<mixed>> {
if (__DEV__) {
const owner = ReactCurrentOwner.current;
Expand All @@ -70,10 +70,14 @@ function findHostInstance_DEPRECATED(
if (componentOrHandle == null) {
return null;
}
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
if (componentOrHandle._nativeTag) {
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return componentOrHandle;
}
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
if (componentOrHandle.canonical && componentOrHandle.canonical._nativeTag) {
// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return componentOrHandle.canonical;
}
let hostInstance;
Expand Down Expand Up @@ -194,10 +198,10 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
}

function render(
element: React$Element<any>,
containerTag: any,
callback: ?Function,
) {
element: Element<ElementType>,
containerTag: number,
callback: ?() => void,
): ?ElementRef<ElementType> {
let root = roots.get(containerTag);

if (!root) {
Expand All @@ -208,6 +212,7 @@ function render(
}
updateContainer(element, root, null, callback);

// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return getPublicRootInstance(root);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
ReactNativeBaseComponentViewConfig,
ViewConfig,
TouchedViewDataAtPoint,
} from './ReactNativeTypes';

Expand Down Expand Up @@ -111,13 +111,13 @@ if (registerEventHandler) {
*/
class ReactFabricHostComponent {
_nativeTag: number;
viewConfig: ReactNativeBaseComponentViewConfig<>;
viewConfig: ViewConfig;
currentProps: Props;
_internalInstanceHandle: Object;

constructor(
tag: number,
viewConfig: ReactNativeBaseComponentViewConfig<>,
viewConfig: ViewConfig,
props: Props,
internalInstanceHandle: Object,
) {
Expand Down
26 changes: 13 additions & 13 deletions packages/react-native-renderer/src/ReactNativeAttributePayload.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function defaultDiffer(prevProp: mixed, nextProp: mixed): boolean {
function restoreDeletedValuesInNestedArray(
updatePayload: Object,
node: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
) {
if (Array.isArray(node)) {
let i = node.length;
Expand Down Expand Up @@ -107,7 +107,7 @@ function diffNestedArrayProperty(
updatePayload: null | Object,
prevArray: Array<NestedNode>,
nextArray: Array<NestedNode>,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
const minLength =
prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
Expand Down Expand Up @@ -145,7 +145,7 @@ function diffNestedProperty(
updatePayload: null | Object,
prevProp: NestedNode,
nextProp: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
if (!updatePayload && prevProp === nextProp) {
// If no properties have been added, then we can bail out quickly on object
Expand Down Expand Up @@ -206,7 +206,7 @@ function diffNestedProperty(
function addNestedProperty(
updatePayload: null | Object,
nextProp: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
) {
if (!nextProp) {
return updatePayload;
Expand Down Expand Up @@ -236,7 +236,7 @@ function addNestedProperty(
function clearNestedProperty(
updatePayload: null | Object,
prevProp: NestedNode,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
if (!prevProp) {
return updatePayload;
Expand Down Expand Up @@ -268,7 +268,7 @@ function diffProperties(
updatePayload: null | Object,
prevProps: Object,
nextProps: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
let attributeConfig;
let nextProp;
Expand Down Expand Up @@ -369,13 +369,13 @@ function diffProperties(
updatePayload,
prevProp,
nextProp,
((attributeConfig: any): AttributeConfiguration<>),
((attributeConfig: any): AttributeConfiguration),
);
if (removedKeyCount > 0 && updatePayload) {
restoreDeletedValuesInNestedArray(
updatePayload,
nextProp,
((attributeConfig: any): AttributeConfiguration<>),
((attributeConfig: any): AttributeConfiguration),
);
removedKeys = null;
}
Expand Down Expand Up @@ -426,7 +426,7 @@ function diffProperties(
updatePayload = clearNestedProperty(
updatePayload,
prevProp,
((attributeConfig: any): AttributeConfiguration<>),
((attributeConfig: any): AttributeConfiguration),
);
}
}
Expand All @@ -439,7 +439,7 @@ function diffProperties(
function addProperties(
updatePayload: null | Object,
props: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
// TODO: Fast path
return diffProperties(updatePayload, emptyObject, props, validAttributes);
Expand All @@ -452,15 +452,15 @@ function addProperties(
function clearProperties(
updatePayload: null | Object,
prevProps: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
// TODO: Fast path
return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
}

export function create(
props: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
return addProperties(
null, // updatePayload
Expand All @@ -472,7 +472,7 @@ export function create(
export function diff(
prevProps: Object,
nextProps: Object,
validAttributes: AttributeConfiguration<>,
validAttributes: AttributeConfiguration,
): null | Object {
return diffProperties(
null, // updatePayload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
ReactNativeBaseComponentViewConfig,
ViewConfig,
} from './ReactNativeTypes';
import type {Instance} from './ReactNativeHostConfig';

Expand All @@ -34,11 +34,11 @@ class ReactNativeFiberHostComponent {
_children: Array<Instance | number>;
_nativeTag: number;
_internalFiberInstanceHandleDEV: Object;
viewConfig: ReactNativeBaseComponentViewConfig<>;
viewConfig: ViewConfig;

constructor(
tag: number,
viewConfig: ReactNativeBaseComponentViewConfig<>,
viewConfig: ViewConfig,
internalInstanceHandleDEV: Object,
) {
this._nativeTag = tag;
Expand Down
10 changes: 6 additions & 4 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import type {HostComponent} from './ReactNativeTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef, Element, ElementType} from 'react';

import './ReactNativeInjection';

Expand Down Expand Up @@ -193,10 +194,10 @@ function sendAccessibilityEvent(handle: any, eventType: string) {
}

function render(
element: React$Element<any>,
containerTag: any,
callback: ?Function,
) {
element: Element<ElementType>,
containerTag: number,
callback: ?() => void,
): ?ElementRef<ElementType> {
let root = roots.get(containerTag);

if (!root) {
Expand All @@ -207,6 +208,7 @@ function render(
}
updateContainer(element, root, null, callback);

// $FlowIssue Flow has hardcoded values for React DOM that don't work with RN
return getPublicRootInstance(root);
}

Expand Down
Loading

0 comments on commit 6414a56

Please sign in to comment.