shouldSetTextContent accepts type parameter in addition to props (#9841)
Brian Vaughn committed
Jun 2, 2017 at 10:40 UTC
a5d659d07eeeee9b76c150c9350ed0f71b3a5c04
8 files changed
+15
-12
src/renderers/art/ReactARTFiber.js
+1
-1
@@ -513,7 +513,7 @@ const ARTRenderer = ReactFiberReconciler({
513
514
scheduleDeferredCallback: ReactDOMFrameScheduling.rIC,
515
516
- shouldSetTextContent(props) {
516
+ shouldSetTextContent(type, props) {
517
return (
518
typeof props.children === 'string' || typeof props.children === 'number'
519
);
src/renderers/dom/fiber/ReactDOMFiber.js
+1
-1
@@ -302,7 +302,7 @@ var DOMRenderer = ReactFiberReconciler({
302
updateProperties(domElement, updatePayload, type, oldProps, newProps);
303
},
304
305
- shouldSetTextContent(props: Props): boolean {
305
+ shouldSetTextContent(type: string, props: Props): boolean {
306
return (
307
typeof props.children === 'string' ||
308
typeof props.children === 'number' ||
src/renderers/native/ReactNativeFiberRenderer.js
+1
-1
@@ -364,7 +364,7 @@ const NativeRenderer = ReactFiberReconciler({
364
365
scheduleDeferredCallback: global.requestIdleCallback,
366
367
- shouldSetTextContent(props: Props): boolean {
367
+ shouldSetTextContent(type: string, props: Props): boolean {
368
// TODO (bvaughn) Revisit this decision.
369
// Always returning false simplifies the createInstance() implementation,
370
// But creates an additional child Fiber for raw text children.
src/renderers/noop/ReactNoop.js
+1
-1
@@ -113,7 +113,7 @@ var NoopRenderer = ReactFiberReconciler({
113
instance.prop = newProps.prop;
114
},
115
116
- shouldSetTextContent(props: Props): boolean {
116
+ shouldSetTextContent(type: string, props: Props): boolean {
117
return (
118
typeof props.children === 'string' || typeof props.children === 'number'
119
);
src/renderers/shared/fiber/ReactFiberBeginWork.js
+4
-3
@@ -406,6 +406,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
406
}
407
408
let nextProps = workInProgress.pendingProps;
409
+ const type = workInProgress.type;
410
const prevProps = current !== null ? current.memoizedProps : null;
411
const memoizedProps = workInProgress.memoizedProps;
412
if (hasContextChanged()) {
@@ -422,7 +423,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
423
} else if (nextProps === null || memoizedProps === nextProps) {
424
if (
425
!useSyncScheduling &&
425
- shouldDeprioritizeSubtree(workInProgress.type, memoizedProps) &&
426
+ shouldDeprioritizeSubtree(type, memoizedProps) &&
427
workInProgress.pendingWorkPriority !== OffscreenPriority
428
) {
429
// This subtree still has work, but it should be deprioritized so we need
@@ -445,7 +446,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
446
}
447
448
let nextChildren = nextProps.children;
448
- const isDirectTextChild = shouldSetTextContent(nextProps);
449
+ const isDirectTextChild = shouldSetTextContent(type, nextProps);
450
451
if (isDirectTextChild) {
452
// We special case a direct text child of a host node. This is a common
@@ -453,7 +454,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
454
// this in the host environment that also have access to this prop. That
455
// avoids allocating another HostText fiber and traversing it.
456
nextChildren = null;
456
- } else if (prevProps && shouldSetTextContent(prevProps)) {
457
+ } else if (prevProps && shouldSetTextContent(type, prevProps)) {
458
// If we're switching from a direct text child to a normal child, or to
459
// empty, we need to schedule the text content to be reset.
460
workInProgress.effectTag |= ContentReset;
src/renderers/shared/fiber/ReactFiberHydrationContext.js
+5
-3
@@ -192,6 +192,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
192
return false;
193
}
194
195
+ const type = fiber.type;
196
+
197
// If we have any remaining hydratable nodes, we need to delete them now.
198
// We only do this deeper than head and body since they tend to have random
199
// other nodes in them. We also ignore components with pure text content in
@@ -199,9 +201,9 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
201
// TODO: Better heuristic.
202
if (
203
fiber.tag !== HostComponent ||
202
- (fiber.type !== 'head' &&
203
- fiber.type !== 'body' &&
204
- !shouldSetTextContent(fiber.memoizedProps))
204
+ (type !== 'head' &&
205
+ type !== 'body' &&
206
+ !shouldSetTextContent(type, fiber.memoizedProps))
207
) {
208
let nextInstance = nextHydratableInstance;
209
while (nextInstance) {
src/renderers/shared/fiber/ReactFiberReconciler.js
+1
-1
@@ -91,7 +91,7 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
91
internalInstanceHandle: OpaqueHandle,
92
): void,
93
94
- shouldSetTextContent(props: P): boolean,
94
+ shouldSetTextContent(type: T, props: P): boolean,
95
resetTextContent(instance: I): void,
96
shouldDeprioritizeSubtree(type: T, props: P): boolean,
97
src/renderers/testing/ReactTestRendererFiber.js
+1
-1
@@ -145,7 +145,7 @@ var TestRenderer = ReactFiberReconciler({
145
// noop
146
},
147
148
- shouldSetTextContent(props: Props): boolean {
148
+ shouldSetTextContent(type: string, props: Props): boolean {
149
return false;
150
},
151