Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ const bundles = [
label: 'native-cs-fiber',
manglePropertiesOnProd: false,
name: 'react-native-cs-renderer',
featureFlags: 'src/renderers/native-cs/ReactNativeCSFeatureFlags',
paths: [
'src/renderers/native-cs/**/*.js',
'src/renderers/shared/**/*.js',
Expand Down
24 changes: 24 additions & 0 deletions src/renderers/native-cs/ReactNativeCSFeatureFlags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule ReactNativeCSFeatureFlags
* @flow
*/

'use strict';

import type {FeatureFlags} from 'ReactFeatureFlags';

var ReactNativeCSFeatureFlags: FeatureFlags = {
enableAsyncSubtreeAPI: true,
enableAsyncSchedulingByDefaultInReactDOM: false,
// React Native CS uses persistent reconciler.
enableMutatingReconciler: false,
enableNoopReconciler: false,
enablePersistentReconciler: true,
};

module.exports = ReactNativeCSFeatureFlags;
2 changes: 2 additions & 0 deletions src/renderers/native-cs/__tests__/ReactNativeCS-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
var React;
var ReactNativeCS;

jest.mock('ReactFeatureFlags', () => require('ReactNativeCSFeatureFlags'));

describe('ReactNativeCS', () => {
beforeEach(() => {
jest.resetModules();
Expand Down
105 changes: 58 additions & 47 deletions src/renderers/noop/ReactNoopEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import type {Fiber} from 'ReactFiber';
import type {UpdateQueue} from 'ReactFiberUpdateQueue';

var ReactFeatureFlags = require('ReactFeatureFlags');
var ReactFiberInstrumentation = require('ReactFiberInstrumentation');
var ReactFiberReconciler = require('ReactFiberReconciler');
var ReactInstanceMap = require('ReactInstanceMap');
Expand Down Expand Up @@ -214,53 +215,58 @@ var NoopRenderer = ReactFiberReconciler({
},
});

var PersistentNoopRenderer = ReactFiberReconciler({
...SharedHostConfig,
persistence: {
cloneInstance(
instance: Instance,
updatePayload: null | Object,
type: string,
oldProps: Props,
newProps: Props,
internalInstanceHandle: Object,
keepChildren: boolean,
recyclableInstance: null | Instance,
): Instance {
const clone = {
id: instance.id,
type: type,
children: keepChildren ? instance.children : [],
prop: newProps.prop,
};
Object.defineProperty(clone, 'id', {
value: clone.id,
enumerable: false,
});
return clone;
},

cloneContainer(
container: Container,
recyclableContainer: Container,
): Container {
return {rootID: container.rootID, children: []};
},

appendInititalChildToContainer(
parentInstance: Container,
child: Instance | TextInstance,
) {
parentInstance.children.push(child);
},

finalizeContainerChildren(container: Container): void {},

replaceContainer(oldContainer: Container, newContainer: Container): void {
rootContainers.set(oldContainer.rootID, newContainer);
},
},
});
var PersistentNoopRenderer = ReactFeatureFlags.enablePersistentReconciler
? ReactFiberReconciler({
...SharedHostConfig,
persistence: {
cloneInstance(
instance: Instance,
updatePayload: null | Object,
type: string,
oldProps: Props,
newProps: Props,
internalInstanceHandle: Object,
keepChildren: boolean,
recyclableInstance: null | Instance,
): Instance {
const clone = {
id: instance.id,
type: type,
children: keepChildren ? instance.children : [],
prop: newProps.prop,
};
Object.defineProperty(clone, 'id', {
value: clone.id,
enumerable: false,
});
return clone;
},

cloneContainer(
container: Container,
recyclableContainer: Container,
): Container {
return {rootID: container.rootID, children: []};
},

appendInititalChildToContainer(
parentInstance: Container,
child: Instance | TextInstance,
) {
parentInstance.children.push(child);
},

finalizeContainerChildren(container: Container): void {},

replaceContainer(
oldContainer: Container,
newContainer: Container,
): void {
rootContainers.set(oldContainer.rootID, newContainer);
},
},
})
: null;

var rootContainers = new Map();
var roots = new Map();
Expand Down Expand Up @@ -332,6 +338,11 @@ var ReactNoop = {
rootID: string,
callback: ?Function,
) {
if (PersistentNoopRenderer === null) {
throw new Error(
'Enable ReactFeatureFlags.enablePersistentReconciler to use it in tests.',
);
}
let root = persistentRoots.get(rootID);
if (!root) {
const container = {rootID: rootID, children: []};
Expand Down
90 changes: 53 additions & 37 deletions src/renderers/shared/fiber/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import type {Fiber} from 'ReactFiber';
import type {HostConfig} from 'ReactFiberReconciler';

var ReactFeatureFlags = require('ReactFeatureFlags');
var ReactTypeOfWork = require('ReactTypeOfWork');
var {
ClassComponent,
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
config: HostConfig<T, P, I, TI, PI, C, CX, PL>,
captureError: (failedFiber: Fiber, error: mixed) => Fiber | null,
) {
const {getPublicInstance} = config;
const {getPublicInstance, mutation, persistence} = config;

if (__DEV__) {
var callComponentWillUnmountWithTimerInDev = function(current, instance) {
Expand Down Expand Up @@ -226,9 +227,12 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// TODO: this is recursive.
// We are also not using this parent because
// the portal will get pushed immediately.
if (config.mutation) {
if (ReactFeatureFlags.enableMutatingReconciler && mutation) {
unmountHostComponents(current);
} else if (config.persistence) {
} else if (
ReactFeatureFlags.enablePersistentReconciler &&
persistence
) {
emptyPortalContainer(current);
}
return;
Expand All @@ -250,7 +254,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
if (
node.child !== null &&
// Drill down into portals only if we use mutation since that branch is recursive
(!config.mutation || node.tag !== HostPortal)
(!mutation || node.tag !== HostPortal)
) {
node.child.return = node;
node = node.child;
Expand Down Expand Up @@ -284,14 +288,10 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
}

if (!config.mutation) {
if (!mutation) {
let commitContainer;
if (!config.persistence) {
commitContainer = function(finishedWork: Fiber) {
// Noop
};
} else {
const {replaceContainer, cloneContainer} = config.persistence;
if (persistence) {
const {replaceContainer, cloneContainer} = persistence;
var emptyPortalContainer = function(current: Fiber) {
const portal: {containerInfo: C, pendingContainerInfo: C} =
current.stateNode;
Expand Down Expand Up @@ -334,24 +334,36 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
}
};
} else {
commitContainer = function(finishedWork: Fiber) {
// Noop
};
}
if (
ReactFeatureFlags.enablePersistentReconciler ||
ReactFeatureFlags.enableNoopReconciler
) {
return {
commitResetTextContent(finishedWork: Fiber) {},
commitPlacement(finishedWork: Fiber) {},
commitDeletion(current: Fiber) {
// Detach refs and call componentWillUnmount() on the whole subtree.
commitNestedUnmounts(current);
detachFiber(current);
},
commitWork(current: Fiber | null, finishedWork: Fiber) {
commitContainer(finishedWork);
},
commitLifeCycles,
commitAttachRef,
commitDetachRef,
};
} else if (persistence) {
invariant(false, 'Persistent reconciler is disabled.');
} else {
invariant(false, 'Noop reconciler is disabled.');
}
return {
commitResetTextContent(finishedWork: Fiber) {},
commitPlacement(finishedWork: Fiber) {},
commitDeletion(current: Fiber) {
// Detach refs and call componentWillUnmount() on the whole subtree.
commitNestedUnmounts(current);
detachFiber(current);
},
commitWork(current: Fiber | null, finishedWork: Fiber) {
commitContainer(finishedWork);
},
commitLifeCycles,
commitAttachRef,
commitDetachRef,
};
}

const {
commitMount,
commitUpdate,
Expand All @@ -363,7 +375,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
insertInContainerBefore,
removeChild,
removeChildFromContainer,
} = config.mutation;
} = mutation;

function getHostParentFiber(fiber: Fiber): Fiber {
let parent = fiber.return;
Expand Down Expand Up @@ -663,13 +675,17 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
resetTextContent(current.stateNode);
}

return {
commitResetTextContent,
commitPlacement,
commitDeletion,
commitWork,
commitLifeCycles,
commitAttachRef,
commitDetachRef,
};
if (ReactFeatureFlags.enableMutatingReconciler) {
return {
commitResetTextContent,
commitPlacement,
commitDeletion,
commitWork,
commitLifeCycles,
commitAttachRef,
commitDetachRef,
};
} else {
invariant(false, 'Mutating reconciler is disabled.');
}
};
Loading