Skip to content

Commit 2da35fc

Browse files
iamdustangaearon
authored andcommitted
[Fiber] Implement test renderer (#8628)
* ReactTestRenderer move current impl to stack dir * ReactTestRenderer on fiber: commence! * ReactTestRenderer: most non-ref/non-public-instance tests are passing * Move ReactTestFiberComponent functions from Renderer to Component file * test renderer: get rid of private root containers and root Maps * TestRenderer: switch impl based on ReactDOMFeatureFlag.useFiber * ReactTestRenderer: inline component creation * ReactTestRenderer: return to pristine original glory (+ Fiber for error order difference) * TestRendererFiber: use a simple class as TestComponentInstances * Add `getPublicInstance` to support TestRenderer `createNodeMock` * Rename files to end. Update for `mountContainer->createContainer` change * test renderer return same object to prevent unnecessary context pushing/popping * Fiber HostConfig add getPublicInstance. This should be the identity fn everywhere except the test renderer * appease flow * Initial cleanup from sleepy work * unstable_batchedUpdates * Stack test renderer: cache nodeMock to not call on unmount * add public instance type parameter to the reconciler * test renderer: set _nodeMock when mounted * More cleanup * Add test cases for root fragments and (maybe?) root text nodes * Fix the npm package build Explicitly require the Stack version by default. Add a separate entry point for Fiber. We don't add fiber.js to the package yet since it's considered internal until React 16. * Relax the ref type from Object to mixed This seems like the most straightforward way to support getPublicInstance for test renderer. * Remove accidental newline * test renderer: unify TestComponent and TestContainer, handle root updates * Remove string/number serialization attempts since Fiber ensures all textInstances are strings * Return full fragments in toJSON * Test Renderer remove TestComponent instances for simple objects * Update babylon for exact object type syntax * Use $$typeof because clarity > punching ducks. * Minor Flow annotation tweaks * Tweak style, types, and naming * Fix typo
1 parent 837835d commit 2da35fc

24 files changed

+630
-174
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"babel-plugin-transform-react-jsx-source": "^6.8.0",
3434
"babel-preset-react": "^6.5.0",
3535
"babel-traverse": "^6.9.0",
36-
"babylon": "6.8.0",
36+
"babylon": "6.15.0",
3737
"browserify": "^13.0.0",
3838
"bundle-collapser": "^1.1.1",
3939
"coffee-script": "^1.8.0",

packages/react-test-renderer/fiber.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('./lib/ReactTestRendererFiber');

packages/react-test-renderer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
'use strict';
22

3-
module.exports = require('./lib/ReactTestRenderer');
3+
module.exports = require('./lib/ReactTestRendererStack');

scripts/fiber/tests-passing.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,7 @@ src/renderers/testing/__tests__/ReactTestRenderer-test.js
16751675
* renders a simple component
16761676
* renders a top-level empty component
16771677
* exposes a type flag
1678+
* can render a composite component
16781679
* renders some basics with an update
16791680
* exposes the instance
16801681
* updates types
@@ -1687,6 +1688,9 @@ src/renderers/testing/__tests__/ReactTestRenderer-test.js
16871688
* supports unmounting inner instances
16881689
* supports updates when using refs
16891690
* supports error boundaries
1691+
* can update text nodes
1692+
* can update text nodes when rendered as root
1693+
* can render and update root fragments
16901694

16911695
src/shared/utils/__tests__/KeyEscapeUtils-test.js
16921696
* should properly escape and wrap user defined keys

src/renderers/art/ReactARTFiber.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ const ARTRenderer = ReactFiberReconciler({
464464
return false;
465465
},
466466

467+
getPublicInstance(instance) {
468+
return instance;
469+
},
470+
467471
insertBefore(parentInstance, child, beforeChild) {
468472
invariant(
469473
child !== beforeChild,

src/renderers/dom/fiber/ReactDOMFiber.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ var DOMRenderer = ReactFiberReconciler({
137137
return getChildNamespace(parentNamespace, type);
138138
},
139139

140+
getPublicInstance(instance) {
141+
return instance;
142+
},
143+
140144
prepareForCommit() : void {
141145
eventsEnabled = ReactBrowserEventEmitter.isEnabled();
142146
selectionInformation = ReactInputSelection.getSelectionInformation();

src/renderers/native/ReactNativeFiber.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ const NativeRenderer = ReactFiberReconciler({
232232
return emptyObject;
233233
},
234234

235+
getPublicInstance(instance) {
236+
return instance;
237+
},
238+
235239
insertBefore(
236240
parentInstance : Instance | Container,
237241
child : Instance | TextInstance,

src/renderers/noop/ReactNoop.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ var NoopRenderer = ReactFiberReconciler({
5454
return emptyObject;
5555
},
5656

57+
getPublicInstance(instance) {
58+
return instance;
59+
},
60+
5761
createInstance(type : string, props : Props) : Instance {
5862
const inst = {
5963
id: instanceCounter++,

src/renderers/shared/fiber/ReactFiber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export type Fiber = {
102102

103103
// The ref last used to attach this node.
104104
// I'll avoid adding an owner field for prod and model that as functions.
105-
ref: null | (((handle : ?Object) => void) & { _stringRef: ?string }),
105+
ref: null | (((handle : mixed) => void) & { _stringRef: ?string }),
106106

107107
// Input is the data coming into process this fiber. Arguments. Props.
108108
pendingProps: any, // This type will be more specific once we overload the tag.

src/renderers/shared/fiber/ReactFiberBeginWork.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ if (__DEV__) {
7171
var warnedAboutStatelessRefs = {};
7272
}
7373

74-
module.exports = function<T, P, I, TI, C, CX>(
75-
config : HostConfig<T, P, I, TI, C, CX>,
74+
module.exports = function<T, P, I, TI, PI, C, CX>(
75+
config : HostConfig<T, P, I, TI, PI, C, CX>,
7676
hostContext : HostContext<C, CX>,
7777
scheduleUpdate : (fiber : Fiber, priorityLevel : PriorityLevel) => void,
7878
getPriorityContext : () => PriorityLevel,

0 commit comments

Comments
 (0)