mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
shouldSetTextContent accepts type parameter in addition to props (#9841)
This commit is contained in:
1 parent
8b6b2f26c4
commit
a5d659d07e
8 files changed
+15
-12
No files matched your search
@@ -513,7 +513,7 @@ const ARTRenderer = ReactFiberReconciler({
|
||||
|
||||
scheduleDeferredCallback: ReactDOMFrameScheduling.rIC,
|
||||
|
||||
shouldSetTextContent(props) {
|
||||
shouldSetTextContent(type, props) {
|
||||
return (
|
||||
typeof props.children === 'string' || typeof props.children === 'number'
|
||||
);
|
||||
|
||||
@@ -302,7 +302,7 @@ var DOMRenderer = ReactFiberReconciler({
|
||||
updateProperties(domElement, updatePayload, type, oldProps, newProps);
|
||||
},
|
||||
|
||||
shouldSetTextContent(props: Props): boolean {
|
||||
shouldSetTextContent(type: string, props: Props): boolean {
|
||||
return (
|
||||
typeof props.children === 'string' ||
|
||||
typeof props.children === 'number' ||
|
||||
|
||||
@@ -364,7 +364,7 @@ const NativeRenderer = ReactFiberReconciler({
|
||||
|
||||
scheduleDeferredCallback: global.requestIdleCallback,
|
||||
|
||||
shouldSetTextContent(props: Props): boolean {
|
||||
shouldSetTextContent(type: string, props: Props): boolean {
|
||||
// TODO (bvaughn) Revisit this decision.
|
||||
// Always returning false simplifies the createInstance() implementation,
|
||||
// But creates an additional child Fiber for raw text children.
|
||||
|
||||
@@ -113,7 +113,7 @@ var NoopRenderer = ReactFiberReconciler({
|
||||
instance.prop = newProps.prop;
|
||||
},
|
||||
|
||||
shouldSetTextContent(props: Props): boolean {
|
||||
shouldSetTextContent(type: string, props: Props): boolean {
|
||||
return (
|
||||
typeof props.children === 'string' || typeof props.children === 'number'
|
||||
);
|
||||
|
||||
@@ -406,6 +406,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
|
||||
}
|
||||
|
||||
let nextProps = workInProgress.pendingProps;
|
||||
const type = workInProgress.type;
|
||||
const prevProps = current !== null ? current.memoizedProps : null;
|
||||
const memoizedProps = workInProgress.memoizedProps;
|
||||
if (hasContextChanged()) {
|
||||
@@ -422,7 +423,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
|
||||
} else if (nextProps === null || memoizedProps === nextProps) {
|
||||
if (
|
||||
!useSyncScheduling &&
|
||||
shouldDeprioritizeSubtree(workInProgress.type, memoizedProps) &&
|
||||
shouldDeprioritizeSubtree(type, memoizedProps) &&
|
||||
workInProgress.pendingWorkPriority !== OffscreenPriority
|
||||
) {
|
||||
// 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>(
|
||||
}
|
||||
|
||||
let nextChildren = nextProps.children;
|
||||
const isDirectTextChild = shouldSetTextContent(nextProps);
|
||||
const isDirectTextChild = shouldSetTextContent(type, nextProps);
|
||||
|
||||
if (isDirectTextChild) {
|
||||
// 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>(
|
||||
// this in the host environment that also have access to this prop. That
|
||||
// avoids allocating another HostText fiber and traversing it.
|
||||
nextChildren = null;
|
||||
} else if (prevProps && shouldSetTextContent(prevProps)) {
|
||||
} else if (prevProps && shouldSetTextContent(type, prevProps)) {
|
||||
// If we're switching from a direct text child to a normal child, or to
|
||||
// empty, we need to schedule the text content to be reset.
|
||||
workInProgress.effectTag |= ContentReset;
|
||||
|
||||
@@ -192,6 +192,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
|
||||
return false;
|
||||
}
|
||||
|
||||
const type = fiber.type;
|
||||
|
||||
// If we have any remaining hydratable nodes, we need to delete them now.
|
||||
// We only do this deeper than head and body since they tend to have random
|
||||
// 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>(
|
||||
// TODO: Better heuristic.
|
||||
if (
|
||||
fiber.tag !== HostComponent ||
|
||||
(fiber.type !== 'head' &&
|
||||
fiber.type !== 'body' &&
|
||||
!shouldSetTextContent(fiber.memoizedProps))
|
||||
(type !== 'head' &&
|
||||
type !== 'body' &&
|
||||
!shouldSetTextContent(type, fiber.memoizedProps))
|
||||
) {
|
||||
let nextInstance = nextHydratableInstance;
|
||||
while (nextInstance) {
|
||||
|
||||
@@ -91,7 +91,7 @@ export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
|
||||
internalInstanceHandle: OpaqueHandle,
|
||||
): void,
|
||||
|
||||
shouldSetTextContent(props: P): boolean,
|
||||
shouldSetTextContent(type: T, props: P): boolean,
|
||||
resetTextContent(instance: I): void,
|
||||
shouldDeprioritizeSubtree(type: T, props: P): boolean,
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ var TestRenderer = ReactFiberReconciler({
|
||||
// noop
|
||||
},
|
||||
|
||||
shouldSetTextContent(props: Props): boolean {
|
||||
shouldSetTextContent(type: string, props: Props): boolean {
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
Reference in new issue
Block a user