Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d76eab1
Update build size
sebmarkbage Oct 18, 2017
9d0a1f0
[CS] Clone container instead of new root concept
sebmarkbage Oct 17, 2017
eba046a
Change the signature or persistence again
sebmarkbage Oct 17, 2017
8a21e26
Implement persistent updates
sebmarkbage Oct 17, 2017
33163d5
Refine protocol into a complete and commit phase
sebmarkbage Oct 17, 2017
1bde3dd
Implement persistent updates of roots and portals
sebmarkbage Oct 17, 2017
bb4ccc4
Commit persistent work at the end by swapping out the container
sebmarkbage Oct 17, 2017
cf738c5
Unify cloneOrRecycle
sebmarkbage Oct 17, 2017
8bb6538
Add persistent noop renderer for testing
sebmarkbage Oct 17, 2017
9b9344c
Add basic persistent tree test
sebmarkbage Oct 18, 2017
a1a8249
Test bail out
sebmarkbage Oct 18, 2017
9b90f54
Test persistent text nodes
sebmarkbage Oct 18, 2017
fc963ad
Add persistent portal test
sebmarkbage Oct 18, 2017
c3d6ee9
Don't consider container when determining portal identity
sebmarkbage Oct 18, 2017
a6b2638
Clear portals when the portal is deleted
sebmarkbage Oct 18, 2017
5d461e0
Add renderer mode flags for dead code elimination
gaearon Oct 18, 2017
837a6d9
Simplify ReactNoop fix
gaearon Oct 18, 2017
25638ef
Add new type to the host config for persistent configs
sebmarkbage Oct 18, 2017
c9b7e56
Implement new hooks
sebmarkbage Oct 18, 2017
c6ff79c
Update build size and error codes
sebmarkbage Oct 18, 2017
2f8d55b
Address comment
sebmarkbage Oct 18, 2017
bf043dd
Move new files to new location
sebmarkbage Oct 18, 2017
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
24 changes: 24 additions & 0 deletions packages/react-cs-renderer/src/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;
39 changes: 21 additions & 18 deletions packages/react-cs-renderer/src/ReactNativeCSFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,37 @@ const ReactNativeCSFiberRenderer = ReactFiberReconciler({
persistence: {
cloneInstance(
instance: Instance,
updatePayload: Object,
type: string,
oldProps: Props,
newProps: Props,
internalInstanceHandle: Object,
keepChildren: boolean,
): Instance {
return 0;
},
tryToReuseInstance(
instance: Instance,
updatePayload: Object,
updatePayload: null | Object,
type: string,
oldProps: Props,
newProps: Props,
internalInstanceHandle: Object,
keepChildren: boolean,
recyclableInstance: null | Instance,
): Instance {
return 0;
},

createRootInstance(
rootContainerInstance: Container,
hostContext: {},
): Instance {
return 123;
createContainerChildSet(
container: Container,
): Array<Instance | TextInstance> {
return [];
},
commitRootInstance(rootInstance: Instance): void {},

appendChildToContainerChildSet(
childSet: Array<Instance | TextInstance>,
child: Instance | TextInstance,
): void {},

finalizeContainerChildren(
container: Container,
newChildren: Array<Instance | TextInstance>,
): void {},

replaceContainerChildren(
container: Container,
newChildren: Array<Instance | TextInstance>,
): void {},
},
});

Expand Down
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
82 changes: 81 additions & 1 deletion packages/react-noop-renderer/src/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 @@ -85,7 +86,7 @@ function removeChild(

let elapsedTimeInMs = 0;

var NoopRenderer = ReactFiberReconciler({
var SharedHostConfig = {
getRootHostContext() {
if (failInBeginPhase) {
throw new Error('Error in host config.');
Expand Down Expand Up @@ -176,7 +177,10 @@ var NoopRenderer = ReactFiberReconciler({
now(): number {
return elapsedTimeInMs;
},
};

var NoopRenderer = ReactFiberReconciler({
...SharedHostConfig,
mutation: {
commitMount(instance: Instance, type: string, newProps: Props): void {
// Noop
Expand Down Expand Up @@ -211,8 +215,64 @@ var NoopRenderer = ReactFiberReconciler({
},
});

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;
},

createContainerChildSet(
container: Container,
): Array<Instance | TextInstance> {
return [];
},

appendChildToContainerChildSet(
childSet: Array<Instance | TextInstance>,
child: Instance | TextInstance,
): void {
childSet.push(child);
},

finalizeContainerChildren(
container: Container,
newChildren: Array<Instance | TextInstance>,
): void {},

replaceContainerChildren(
container: Container,
newChildren: Array<Instance | TextInstance>,
): void {
container.children = newChildren;
},
},
})
: null;

var rootContainers = new Map();
var roots = new Map();
var persistentRoots = new Map();
var DEFAULT_ROOT_ID = '<default>';

let yieldedValues = null;
Expand Down Expand Up @@ -275,6 +335,26 @@ var ReactNoop = {
NoopRenderer.updateContainer(element, root, null, callback);
},

renderToPersistentRootWithID(
element: React$Element<any>,
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: []};
rootContainers.set(rootID, container);
root = PersistentNoopRenderer.createContainer(container, false);
persistentRoots.set(rootID, root);
}
PersistentNoopRenderer.updateContainer(element, root, null, callback);
},

unmountRootWithID(rootID: string) {
const root = roots.get(rootID);
if (root) {
Expand Down
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ exports.createFiberFromPortal = function(
fiber.expirationTime = expirationTime;
fiber.stateNode = {
containerInfo: portal.containerInfo,
pendingChildren: null, // Used by persistent updates
implementation: portal.implementation,
};
return fiber;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ if (__DEV__) {
var warnedAboutStatelessRefs = {};
}

module.exports = function<T, P, I, TI, PI, C, CX, PL>(
config: HostConfig<T, P, I, TI, PI, C, CX, PL>,
module.exports = function<T, P, I, TI, PI, C, CC, CX, PL>(
config: HostConfig<T, P, I, TI, PI, C, CC, CX, PL>,
hostContext: HostContext<C, CX>,
hydrationContext: HydrationContext<C, CX>,
scheduleWork: (fiber: Fiber, expirationTime: ExpirationTime) => void,
Expand Down
Loading