Move ReactFiberTreeReflection to react-reconciler/reflection (#11683)

* Move ReactFiberTreeReflection to react-reconciler/reflection #11659

* Use * for react-reconciler

We don't know the latest local version, and release script currently doesn't bump deps automatically.

* Remove unused field

* Use CommonJS in entry point for consistency

* Undo the CommonJS change

I didn't realize it would break the build.

* Record sizes

* Remove reconciler fixtures

They're unnecessary now that we run real tests on reconciler bundles.
This commit is contained in:
rivenhk
2017-11-29 00:57:22 +08:00
committed by Dan Abramov
parent db0454134c
commit 8e876d244c
22 changed files with 58 additions and 536 deletions
-14
View File
@@ -1,14 +0,0 @@
# React Reconciler Test Fixture
This folder exists for **React contributors** only.
If you use React you don't need to worry about it.
These fixtures are a smoke-screen verification that the built React Reconciler distribution works.
To test, from the project root:
* `yarn build`
* `cd fixtures/reconciler`
* `yarn`
* `yarn test`
They should run as part of the CI check.
-371
View File
@@ -1,371 +0,0 @@
/**
* This is a renderer of React that doesn't have a render target output.
* It is used to test that the react-reconciler package doesn't blow up.
*
* @flow
*/
'use strict';
var React = require('react');
var assert = require('assert');
var ReactFiberReconciler = require('react-reconciler');
var emptyObject = require('fbjs/lib/emptyObject');
var assert = require('assert');
const UPDATE_SIGNAL = {};
var scheduledCallback = null;
type Container = {rootID: string, children: Array<Instance | TextInstance>};
type Props = {prop: any, hidden?: boolean};
type Instance = {|
type: string,
id: number,
children: Array<Instance | TextInstance>,
prop: any,
|};
type TextInstance = {|text: string, id: number|};
var instanceCounter = 0;
function appendChild(
parentInstance: Instance | Container,
child: Instance | TextInstance
): void {
const index = parentInstance.children.indexOf(child);
if (index !== -1) {
parentInstance.children.splice(index, 1);
}
parentInstance.children.push(child);
}
function insertBefore(
parentInstance: Instance | Container,
child: Instance | TextInstance,
beforeChild: Instance | TextInstance
): void {
const index = parentInstance.children.indexOf(child);
if (index !== -1) {
parentInstance.children.splice(index, 1);
}
const beforeIndex = parentInstance.children.indexOf(beforeChild);
if (beforeIndex === -1) {
throw new Error('This child does not exist.');
}
parentInstance.children.splice(beforeIndex, 0, child);
}
function removeChild(
parentInstance: Instance | Container,
child: Instance | TextInstance
): void {
const index = parentInstance.children.indexOf(child);
if (index === -1) {
throw new Error('This child does not exist.');
}
parentInstance.children.splice(index, 1);
}
var NoopRenderer = ReactFiberReconciler({
getRootHostContext() {
return emptyObject;
},
getChildHostContext() {
return emptyObject;
},
getPublicInstance(instance) {
return instance;
},
createInstance(type: string, props: Props): Instance {
const inst = {
id: instanceCounter++,
type: type,
children: [],
prop: props.prop,
};
// Hide from unit tests
Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false});
return inst;
},
appendInitialChild(
parentInstance: Instance,
child: Instance | TextInstance
): void {
parentInstance.children.push(child);
},
finalizeInitialChildren(
domElement: Instance,
type: string,
props: Props
): boolean {
return false;
},
prepareUpdate(
instance: Instance,
type: string,
oldProps: Props,
newProps: Props
): null | {} {
return UPDATE_SIGNAL;
},
shouldSetTextContent(type: string, props: Props): boolean {
return (
typeof props.children === 'string' || typeof props.children === 'number'
);
},
shouldDeprioritizeSubtree(type: string, props: Props): boolean {
return !!props.hidden;
},
now: Date.now,
createTextInstance(
text: string,
rootContainerInstance: Container,
hostContext: Object,
internalInstanceHandle: Object
): TextInstance {
var inst = {text: text, id: instanceCounter++};
// Hide from unit tests
Object.defineProperty(inst, 'id', {value: inst.id, enumerable: false});
return inst;
},
scheduleDeferredCallback(callback) {
if (scheduledCallback) {
throw new Error(
'Scheduling a callback twice is excessive. Instead, keep track of ' +
'whether the callback has already been scheduled.'
);
}
scheduledCallback = callback;
},
prepareForCommit(): void {},
resetAfterCommit(): void {},
mutation: {
commitMount(instance: Instance, type: string, newProps: Props): void {
// Noop
},
commitUpdate(
instance: Instance,
updatePayload: Object,
type: string,
oldProps: Props,
newProps: Props
): void {
instance.prop = newProps.prop;
},
commitTextUpdate(
textInstance: TextInstance,
oldText: string,
newText: string
): void {
textInstance.text = newText;
},
appendChild: appendChild,
appendChildToContainer: appendChild,
insertBefore: insertBefore,
insertInContainerBefore: insertBefore,
removeChild: removeChild,
removeChildFromContainer: removeChild,
resetTextContent(instance: Instance): void {},
},
});
var rootContainers = new Map();
var roots = new Map();
var DEFAULT_ROOT_ID = '<default>';
let yieldedValues = null;
function* flushUnitsOfWork(n: number): Generator<Array<mixed>, void, void> {
var didStop = false;
while (!didStop && scheduledCallback !== null) {
var cb = scheduledCallback;
scheduledCallback = null;
yieldedValues = null;
var unitsRemaining = n;
cb({
timeRemaining() {
if (yieldedValues !== null) {
return 0;
}
if (unitsRemaining-- > 0) {
return 999;
}
didStop = true;
return 0;
},
});
if (yieldedValues !== null) {
const values = yieldedValues;
yieldedValues = null;
yield values;
}
}
}
var Noop = {
getChildren(rootID: string = DEFAULT_ROOT_ID) {
const container = rootContainers.get(rootID);
if (container) {
return container.children;
} else {
return null;
}
},
// Shortcut for testing a single root
render(element: React$Element<any>, callback: ?Function) {
Noop.renderToRootWithID(element, DEFAULT_ROOT_ID, callback);
},
renderToRootWithID(
element: React$Element<any>,
rootID: string,
callback: ?Function
) {
let root = roots.get(rootID);
if (!root) {
const container = {rootID: rootID, children: []};
rootContainers.set(rootID, container);
root = NoopRenderer.createContainer(container);
roots.set(rootID, root);
}
NoopRenderer.updateContainer(element, root, null, callback);
},
flush(): Array<mixed> {
return Noop.flushUnitsOfWork(Infinity);
},
flushUnitsOfWork(n: number): Array<mixed> {
let values = [];
for (const value of flushUnitsOfWork(n)) {
values.push(...value);
}
return values;
},
batchedUpdates: NoopRenderer.batchedUpdates,
deferredUpdates: NoopRenderer.deferredUpdates,
unbatchedUpdates: NoopRenderer.unbatchedUpdates,
flushSync: NoopRenderer.flushSync,
};
type TestProps = {|
active: boolean,
|};
type TestState = {|
counter: number,
|};
let instance = null;
class Test extends React.Component<TestProps, TestState> {
state = {counter: 0};
increment() {
this.setState(({counter}) => ({
counter: counter + 1,
}));
}
render() {
return [this.props.active ? 'Active' : 'Inactive', this.state.counter];
}
}
const Children = props => props.children;
Noop.render(
<main>
<div>Hello</div>
<Children>
Hello world
<span>
{'Number '}
{42}
</span>
<Test active={true} ref={t => (instance = t)} />
</Children>
</main>
);
Noop.flush();
const actual1 = Noop.getChildren();
const expected1 = [
{
type: 'main',
children: [
{type: 'div', children: [], prop: undefined},
{text: 'Hello world'},
{
type: 'span',
children: [{text: 'Number '}, {text: '42'}],
prop: undefined,
},
{text: 'Active'},
{text: '0'},
],
prop: undefined,
},
];
assert.deepEqual(
actual1,
expected1,
'Error. Noop.getChildren() returned unexpected value.\nExpected: ' +
JSON.stringify(expected1, null, 2) +
'\n\nActual:\n ' +
JSON.stringify(actual1, null, 2)
);
if (instance === null) {
throw new Error('Expected instance to exist.');
}
instance.increment();
Noop.flush();
const actual2 = Noop.getChildren();
const expected2 = [
{
type: 'main',
children: [
{type: 'div', children: [], prop: undefined},
{text: 'Hello world'},
{
type: 'span',
children: [{text: 'Number '}, {text: '42'}],
prop: undefined,
},
{text: 'Active'},
{text: '1'},
],
prop: undefined,
},
];
assert.deepEqual(
actual2,
expected2,
'Error. Noop.getChildren() returned unexpected value.\nExpected: ' +
JSON.stringify(expected2, null, 2) +
'\n\nActual:\n ' +
JSON.stringify(actual2, null, 2)
);
const beginGreen = '\u001b[32m';
const endGreen = '\u001b[39m';
console.log(beginGreen + 'Reconciler package is OK!' + endGreen);
-14
View File
@@ -1,14 +0,0 @@
{
"name": "react-fixtures",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "file:../../build/packages/react",
"react-reconciler": "file:../../build/packages/react-reconciler"
},
"scripts": {
"test:dev": "../../node_modules/.bin/babel-node ./index",
"test:prod": "NODE_ENV=production ../../node_modules/.bin/babel-node ./index",
"test": "npm run test:dev && npm run test:prod"
}
}
-106
View File
@@ -1,106 +0,0 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
asap@~2.0.3:
version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
core-js@^1.0.0:
version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
encoding@^0.1.11:
version "0.1.12"
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
dependencies:
iconv-lite "~0.4.13"
fbjs@^0.8.16:
version "0.8.16"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
dependencies:
core-js "^1.0.0"
isomorphic-fetch "^2.1.1"
loose-envify "^1.0.0"
object-assign "^4.1.0"
promise "^7.1.1"
setimmediate "^1.0.5"
ua-parser-js "^0.7.9"
iconv-lite@~0.4.13:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
is-stream@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
isomorphic-fetch@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"
js-tokens@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
dependencies:
js-tokens "^3.0.0"
node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
dependencies:
encoding "^0.1.11"
is-stream "^1.0.1"
object-assign@^4.1.0, object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
promise@^7.1.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
dependencies:
asap "~2.0.3"
prop-types@^15.6.0:
version "15.6.0"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.0.tgz#ceaf083022fc46b4a35f69e13ef75aed0d639856"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.3.1"
object-assign "^4.1.1"
"react-reconciler@file:../../build/packages/react-reconciler":
version "0.1.0"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
"react@file:../../build/packages/react":
version "16.0.0"
dependencies:
fbjs "^0.8.16"
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.0"
setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
ua-parser-js@^0.7.9:
version "0.7.17"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac"
whatwg-fetch@>=0.10.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84"
+1 -1
View File
@@ -7,7 +7,7 @@
* @flow
*/
import * as ReactFiberTreeReflection from 'shared/ReactFiberTreeReflection';
import * as ReactFiberTreeReflection from 'react-reconciler/reflection';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
// TODO: direct imports like some-package/src/* are bad. Fix me.
import * as ReactFiberErrorLogger from 'react-reconciler/src/ReactFiberErrorLogger';
+1 -1
View File
@@ -6,7 +6,7 @@
*/
import {batchedUpdates} from 'events/ReactGenericBatching';
import {isFiberMounted} from 'shared/ReactFiberTreeReflection';
import {isFiberMounted} from 'react-reconciler/reflection';
import {HostRoot} from 'shared/ReactTypeOfWork';
import EventListener from 'fbjs/lib/EventListener';
+1 -1
View File
@@ -7,7 +7,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {findCurrentFiberUsingSlowPath} from 'shared/ReactFiberTreeReflection';
import {findCurrentFiberUsingSlowPath} from 'react-reconciler/reflection';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
import {
ClassComponent,
@@ -12,7 +12,7 @@ import type {Fiber} from 'react-reconciler/src/ReactFiber';
import {
findCurrentHostFiber,
findCurrentFiberUsingSlowPath,
} from 'shared/ReactFiberTreeReflection';
} from 'react-reconciler/reflection';
import getComponentName from 'shared/getComponentName';
import {HostComponent} from 'shared/ReactTypeOfWork';
import emptyObject from 'fbjs/lib/emptyObject';
+2 -1
View File
@@ -10,7 +10,8 @@
"fbjs": "^0.8.16",
"object-assign": "^4.1.1",
"prop-types": "^15.6.0",
"regenerator-runtime": "^0.11.0"
"regenerator-runtime": "^0.11.0",
"react-reconciler": "*"
},
"peerDependencies": {
"react": "^16.0.0"
-7
View File
@@ -17,8 +17,6 @@
import type {Fiber} from 'react-reconciler/src/ReactFiber';
import type {UpdateQueue} from 'react-reconciler/src/ReactFiberUpdateQueue';
// TODO: direct imports like some-package/src/* are bad. Fix me.
import ReactFiberInstrumentation from 'react-reconciler/src/ReactFiberInstrumentation';
import ReactFiberReconciler from 'react-reconciler';
import {enablePersistentReconciler} from 'shared/ReactFeatureFlags';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
@@ -565,11 +563,6 @@ var ReactNoop = {
failInBeginPhase = false;
}
},
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
// Private. Used only by fixtures/fiber-debugger.
ReactFiberInstrumentation,
},
};
export default ReactNoop;
+7
View File
@@ -0,0 +1,7 @@
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-reconciler-reflection.production.min.js');
} else {
module.exports = require('./cjs/react-reconciler-reflection.development.js');
}
+1
View File
@@ -12,6 +12,7 @@
"LICENSE",
"README.md",
"index.js",
"reflection.js",
"cjs/"
],
"main": "index.js",
+12
View File
@@ -0,0 +1,12 @@
/**
* 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.
*
* @flow
*/
'use strict';
export * from './src/ReactFiberTreeReflection';
+1 -1
View File
@@ -15,7 +15,7 @@ import {
debugRenderPhaseSideEffects,
enableAsyncSubtreeAPI,
} from 'shared/ReactFeatureFlags';
import {isMounted} from 'shared/ReactFiberTreeReflection';
import {isMounted} from 'react-reconciler/reflection';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
import emptyObject from 'fbjs/lib/emptyObject';
import getComponentName from 'shared/getComponentName';
+1 -1
View File
@@ -10,7 +10,7 @@
import type {Fiber} from './ReactFiber';
import type {StackCursor} from './ReactFiberStack';
import {isFiberMounted} from 'shared/ReactFiberTreeReflection';
import {isFiberMounted} from 'react-reconciler/reflection';
import {ClassComponent, HostRoot} from 'shared/ReactTypeOfWork';
import getComponentName from 'shared/getComponentName';
import emptyObject from 'fbjs/lib/emptyObject';
+1 -1
View File
@@ -15,7 +15,7 @@ import {enableAsyncSubtreeAPI} from 'shared/ReactFeatureFlags';
import {
findCurrentHostFiber,
findCurrentHostFiberWithNoPortals,
} from 'shared/ReactFiberTreeReflection';
} from 'react-reconciler/reflection';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
import {HostComponent} from 'shared/ReactTypeOfWork';
import emptyObject from 'fbjs/lib/emptyObject';
@@ -12,17 +12,17 @@ import type {Fiber} from 'react-reconciler/src/ReactFiber';
import invariant from 'fbjs/lib/invariant';
import warning from 'fbjs/lib/warning';
import * as ReactInstanceMap from './ReactInstanceMap';
import {ReactCurrentOwner} from './ReactGlobalSharedState';
import getComponentName from './getComponentName';
import * as ReactInstanceMap from 'shared/ReactInstanceMap';
import {ReactCurrentOwner} from 'shared/ReactGlobalSharedState';
import getComponentName from 'shared/getComponentName';
import {
ClassComponent,
HostComponent,
HostRoot,
HostPortal,
HostText,
} from './ReactTypeOfWork';
import {NoEffect, Placement} from './ReactTypeOfSideEffect';
} from 'shared/ReactTypeOfWork';
import {NoEffect, Placement} from 'shared/ReactTypeOfSideEffect';
var MOUNTING = 1;
var MOUNTED = 2;
@@ -10,7 +10,7 @@
import {
findCurrentFiberUsingSlowPath,
findCurrentHostFiber,
} from 'shared/ReactFiberTreeReflection';
} from 'react-reconciler/reflection';
import getComponentName from 'shared/getComponentName';
import {HostComponent} from 'shared/ReactTypeOfWork';
import emptyObject from 'fbjs/lib/emptyObject';
+1 -1
View File
@@ -12,7 +12,7 @@ import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot';
import ReactFiberReconciler from 'react-reconciler';
import {batchedUpdates} from 'events/ReactGenericBatching';
import {findCurrentFiberUsingSlowPath} from 'shared/ReactFiberTreeReflection';
import {findCurrentFiberUsingSlowPath} from 'react-reconciler/reflection';
import emptyObject from 'fbjs/lib/emptyObject';
import {
Fragment,
-5
View File
@@ -10,8 +10,3 @@ yarn build --extract-errors
# Do a sanity check on bundles
yarn lint-build
# Check that the standalone reconciler isn't borked
cd fixtures/reconciler
yarn
yarn test
+10
View File
@@ -211,6 +211,16 @@ const bundles = [
externals: ['react'],
},
/******* Reflection *******/
{
label: 'reconciler-reflection',
moduleType: RENDERER_UTILS,
bundleTypes: [NODE_DEV, NODE_PROD],
entry: 'react-reconciler/reflection',
global: 'ReactFiberTreeReflection',
externals: [],
},
/******* React Call Return (experimental) *******/
{
label: 'react-call-return',
+12 -4
View File
@@ -189,8 +189,8 @@
"gzip": 2725
},
"react-noop-renderer.development.js (NODE_DEV)": {
"size": 277788,
"gzip": 58527
"size": 17474,
"gzip": 4855
},
"react-reconciler.development.js (NODE_DEV)": {
"size": 262177,
@@ -217,8 +217,16 @@
"gzip": 3917
},
"react-noop-renderer.production.min.js (NODE_PROD)": {
"size": 45144,
"gzip": 14079
"size": 6011,
"gzip": 2418
},
"react-reconciler-reflection.development.js (NODE_DEV)": {
"size": 10398,
"gzip": 3198
},
"react-reconciler-reflection.production.min.js (NODE_PROD)": {
"size": 2408,
"gzip": 1062
}
}
}