Skip to content

Commit 36a2afc

Browse files
authored
[CS] Split Host Config Out into a Mutable or Immutable Mode (facebook#11213)
* CS renderer Because we didn't have enough RN experiments. I want to add one more. * Split out hydration from the host config object This makes it easier to do feature detection on the configuration. * Move mutation host config to separate optional object * Refs and life-cycles should happen even in immutable mode * Unmount components even in non-mutation mode This is the same as committing deletions but instead of finding host components to delete, it only invokes componentWillUnmount and detaching of refs. * Add persistent updates API This mode will use a clone based API instead of mutating host instances. Needs implementation still. It's awkward that there can be more than one child inserted into the root. So we need a new API to create a "root" instance so that we can update it atomically. Alternatively we could keep the mutable API for containers and assume that most use cases would only have a single root. * Package up CS renderer * Fix reconciler package fixture
1 parent 339d6cb commit 36a2afc

19 files changed

+1407
-987
lines changed

fixtures/reconciler/index.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,12 @@ var NoopRenderer = ReactFiberReconciler({
115115
return UPDATE_SIGNAL;
116116
},
117117

118-
commitMount(instance: Instance, type: string, newProps: Props): void {
119-
// Noop
120-
},
121-
122-
commitUpdate(
123-
instance: Instance,
124-
updatePayload: Object,
125-
type: string,
126-
oldProps: Props,
127-
newProps: Props
128-
): void {
129-
instance.prop = newProps.prop;
130-
},
131-
132118
shouldSetTextContent(type: string, props: Props): boolean {
133119
return (
134120
typeof props.children === 'string' || typeof props.children === 'number'
135121
);
136122
},
137123

138-
resetTextContent(instance: Instance): void {},
139-
140124
shouldDeprioritizeSubtree(type: string, props: Props): boolean {
141125
return !!props.hidden;
142126
},
@@ -155,21 +139,6 @@ var NoopRenderer = ReactFiberReconciler({
155139
return inst;
156140
},
157141

158-
commitTextUpdate(
159-
textInstance: TextInstance,
160-
oldText: string,
161-
newText: string
162-
): void {
163-
textInstance.text = newText;
164-
},
165-
166-
appendChild: appendChild,
167-
appendChildToContainer: appendChild,
168-
insertBefore: insertBefore,
169-
insertInContainerBefore: insertBefore,
170-
removeChild: removeChild,
171-
removeChildFromContainer: removeChild,
172-
173142
scheduleDeferredCallback(callback) {
174143
if (scheduledCallback) {
175144
throw new Error(
@@ -183,6 +152,39 @@ var NoopRenderer = ReactFiberReconciler({
183152
prepareForCommit(): void {},
184153

185154
resetAfterCommit(): void {},
155+
156+
mutation: {
157+
commitMount(instance: Instance, type: string, newProps: Props): void {
158+
// Noop
159+
},
160+
161+
commitUpdate(
162+
instance: Instance,
163+
updatePayload: Object,
164+
type: string,
165+
oldProps: Props,
166+
newProps: Props
167+
): void {
168+
instance.prop = newProps.prop;
169+
},
170+
171+
commitTextUpdate(
172+
textInstance: TextInstance,
173+
oldText: string,
174+
newText: string
175+
): void {
176+
textInstance.text = newText;
177+
},
178+
179+
appendChild: appendChild,
180+
appendChildToContainer: appendChild,
181+
insertBefore: insertBefore,
182+
insertInContainerBefore: insertBefore,
183+
removeChild: removeChild,
184+
removeChildFromContainer: removeChild,
185+
186+
resetTextContent(instance: Instance): void {},
187+
},
186188
});
187189

188190
var rootContainers = new Map();

scripts/rollup/build.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const Stats = require('./stats');
2121
const syncReactDom = require('./sync').syncReactDom;
2222
const syncReactNative = require('./sync').syncReactNative;
2323
const syncReactNativeRT = require('./sync').syncReactNativeRT;
24+
const syncReactNativeCS = require('./sync').syncReactNativeCS;
2425
const Packaging = require('./packaging');
2526
const Header = require('./header');
2627
const closure = require('rollup-plugin-closure-compiler-js');
@@ -571,6 +572,7 @@ rimraf('build', () => {
571572
Packaging.createFacebookWWWBuild,
572573
Packaging.createReactNativeBuild,
573574
Packaging.createReactNativeRTBuild,
575+
Packaging.createReactNativeCSBuild,
574576
];
575577
for (const bundle of Bundles.bundles) {
576578
tasks.push(
@@ -591,6 +593,9 @@ rimraf('build', () => {
591593
tasks.push(() =>
592594
syncReactNativeRT(join('build', 'react-native-rt'), syncFbsource)
593595
);
596+
tasks.push(() =>
597+
syncReactNativeCS(join('build', 'react-native-cs'), syncFbsource)
598+
);
594599
} else if (syncWww) {
595600
tasks.push(() => syncReactDom(join('build', 'facebook-www'), syncWww));
596601
}

scripts/rollup/bundles.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ const bundles = [
298298
useFiber: true,
299299
},
300300

301-
/******* React Native *******/
301+
/******* React Native RT *******/
302302
{
303303
babelOpts: babelOptsReact,
304304
bundleTypes: [RN_DEV, RN_PROD],
@@ -332,6 +332,32 @@ const bundles = [
332332
useFiber: true,
333333
},
334334

335+
/******* React Native CS *******/
336+
{
337+
babelOpts: babelOptsReact,
338+
bundleTypes: [RN_DEV, RN_PROD],
339+
config: {
340+
destDir: 'build/',
341+
moduleName: 'ReactNativeCSFiber',
342+
sourceMap: false,
343+
},
344+
entry: 'src/renderers/native-cs/ReactNativeCSFiberEntry',
345+
externals: ['prop-types/checkPropTypes'],
346+
hasteName: 'ReactNativeCSFiber',
347+
isRenderer: true,
348+
label: 'native-cs-fiber',
349+
manglePropertiesOnProd: false,
350+
name: 'react-native-cs-renderer',
351+
paths: [
352+
'src/renderers/native-cs/**/*.js',
353+
'src/renderers/shared/**/*.js',
354+
355+
'src/ReactVersion.js',
356+
'src/shared/**/*.js',
357+
],
358+
useFiber: true,
359+
},
360+
335361
/******* React Test Renderer *******/
336362
{
337363
babelOpts: babelOptsReact,

scripts/rollup/packaging.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const reactNativeRTSrcDependencies = [
3333
'src/renderers/native-rt/ReactNativeRTTypes.js',
3434
];
3535

36+
// these files need to be copied to the react-native-cs build
37+
const reactNativeCSSrcDependencies = [
38+
'src/renderers/native-cs/ReactNativeCSTypes.js',
39+
];
40+
3641
function getPackageName(name) {
3742
if (name.indexOf('/') !== -1) {
3843
return name.split('/')[0];
@@ -81,6 +86,25 @@ function createReactNativeRTBuild() {
8186
return Promise.all(promises);
8287
}
8388

89+
function createReactNativeCSBuild() {
90+
// create the react-native-cs folder for FB bundles
91+
fs.mkdirSync(join('build', 'react-native-cs'));
92+
// create the react-native-cs shims folder for FB shims
93+
fs.mkdirSync(join('build', 'react-native-cs', 'shims'));
94+
95+
const to = join('build', 'react-native-cs', 'shims');
96+
97+
let promises = [];
98+
// we also need to copy over some specific files from src
99+
// defined in reactNativeCSSrcDependencies
100+
for (const srcDependency of reactNativeCSSrcDependencies) {
101+
promises.push(
102+
asyncCopyTo(resolve(srcDependency), join(to, basename(srcDependency)))
103+
);
104+
}
105+
return Promise.all(promises);
106+
}
107+
84108
function createFacebookWWWBuild() {
85109
// create the facebookWWW folder for FB bundles
86110
fs.mkdirSync(join('build', facebookWWW));
@@ -191,4 +215,5 @@ module.exports = {
191215
createFacebookWWWBuild,
192216
createReactNativeBuild,
193217
createReactNativeRTBuild,
218+
createReactNativeCSBuild,
194219
};

scripts/rollup/results.json

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@
2525
"gzip": 6703
2626
},
2727
"react-dom.development.js (UMD_DEV)": {
28-
"size": 630418,
29-
"gzip": 145239
28+
"size": 625837,
29+
"gzip": 144320
3030
},
3131
"react-dom.production.min.js (UMD_PROD)": {
32-
"size": 101638,
33-
"gzip": 32128
32+
"size": 100866,
33+
"gzip": 31848
3434
},
3535
"react-dom.development.js (NODE_DEV)": {
36-
"size": 592683,
37-
"gzip": 136496
36+
"size": 588106,
37+
"gzip": 135609
3838
},
3939
"react-dom.production.min.js (NODE_PROD)": {
40-
"size": 106507,
41-
"gzip": 33538
40+
"size": 105343,
41+
"gzip": 33129
4242
},
4343
"ReactDOMFiber-dev.js (FB_DEV)": {
44-
"size": 589582,
45-
"gzip": 135915
44+
"size": 584995,
45+
"gzip": 135013
4646
},
4747
"ReactDOMFiber-prod.js (FB_PROD)": {
48-
"size": 419983,
49-
"gzip": 93676
48+
"size": 414881,
49+
"gzip": 92663
5050
},
5151
"react-dom-test-utils.development.js (NODE_DEV)": {
5252
"size": 41660,
@@ -113,44 +113,44 @@
113113
"gzip": 6214
114114
},
115115
"react-art.development.js (UMD_DEV)": {
116-
"size": 376896,
117-
"gzip": 83318
116+
"size": 372576,
117+
"gzip": 82452
118118
},
119119
"react-art.production.min.js (UMD_PROD)": {
120-
"size": 83700,
121-
"gzip": 25995
120+
"size": 83057,
121+
"gzip": 25828
122122
},
123123
"react-art.development.js (NODE_DEV)": {
124-
"size": 301201,
125-
"gzip": 64095
124+
"size": 296909,
125+
"gzip": 63228
126126
},
127127
"react-art.production.min.js (NODE_PROD)": {
128-
"size": 53531,
129-
"gzip": 16898
128+
"size": 52508,
129+
"gzip": 16427
130130
},
131131
"ReactARTFiber-dev.js (FB_DEV)": {
132-
"size": 300073,
133-
"gzip": 64131
132+
"size": 295771,
133+
"gzip": 63258
134134
},
135135
"ReactARTFiber-prod.js (FB_PROD)": {
136-
"size": 224585,
137-
"gzip": 46566
136+
"size": 219800,
137+
"gzip": 45628
138138
},
139139
"ReactNativeFiber-dev.js (RN_DEV)": {
140-
"size": 283095,
141-
"gzip": 49176
140+
"size": 279764,
141+
"gzip": 48665
142142
},
143143
"ReactNativeFiber-prod.js (RN_PROD)": {
144-
"size": 221913,
145-
"gzip": 38509
144+
"size": 218506,
145+
"gzip": 37873
146146
},
147147
"react-test-renderer.development.js (NODE_DEV)": {
148-
"size": 304971,
149-
"gzip": 64484
148+
"size": 300619,
149+
"gzip": 63624
150150
},
151151
"ReactTestRendererFiber-dev.js (FB_DEV)": {
152-
"size": 303833,
153-
"gzip": 64527
152+
"size": 299471,
153+
"gzip": 63657
154154
},
155155
"react-test-renderer-shallow.development.js (NODE_DEV)": {
156156
"size": 9215,
@@ -161,8 +161,8 @@
161161
"gzip": 2221
162162
},
163163
"react-noop-renderer.development.js (NODE_DEV)": {
164-
"size": 292571,
165-
"gzip": 61440
164+
"size": 288214,
165+
"gzip": 60549
166166
},
167167
"react-dom-server.development.js (UMD_DEV)": {
168168
"size": 120897,
@@ -189,16 +189,16 @@
189189
"gzip": 7520
190190
},
191191
"ReactNativeRTFiber-dev.js (RN_DEV)": {
192-
"size": 215098,
193-
"gzip": 36673
192+
"size": 211687,
193+
"gzip": 36145
194194
},
195195
"ReactNativeRTFiber-prod.js (RN_PROD)": {
196-
"size": 163687,
197-
"gzip": 27527
196+
"size": 160200,
197+
"gzip": 26880
198198
},
199199
"react-test-renderer.production.min.js (NODE_PROD)": {
200-
"size": 55085,
201-
"gzip": 17135
200+
"size": 54076,
201+
"gzip": 16776
202202
},
203203
"react-test-renderer-shallow.production.min.js (NODE_PROD)": {
204204
"size": 4536,
@@ -209,12 +209,20 @@
209209
"gzip": 4241
210210
},
211211
"react-reconciler.development.js (NODE_DEV)": {
212-
"size": 279927,
213-
"gzip": 58576
212+
"size": 275518,
213+
"gzip": 57698
214214
},
215215
"react-reconciler.production.min.js (NODE_PROD)": {
216-
"size": 38630,
217-
"gzip": 12165
216+
"size": 37979,
217+
"gzip": 11842
218+
},
219+
"ReactNativeCSFiber-dev.js (RN_DEV)": {
220+
"size": 204077,
221+
"gzip": 34318
222+
},
223+
"ReactNativeCSFiber-prod.js (RN_PROD)": {
224+
"size": 155097,
225+
"gzip": 25642
218226
}
219227
}
220228
}

0 commit comments

Comments
 (0)