-
Notifications
You must be signed in to change notification settings - Fork 49.2k
[Fiber] disableNewFiberFeatures bugfix: host component children arrays #8797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
16956ed
1ac6be2
5c4362d
c0e5df6
645ad6d
ba1d382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -64,7 +64,6 @@ const { | |||
FunctionalComponent, | ||||
ClassComponent, | ||||
HostText, | ||||
HostRoot, | ||||
HostPortal, | ||||
CoroutineComponent, | ||||
YieldComponent, | ||||
|
@@ -75,7 +74,6 @@ const { | |||
NoEffect, | ||||
Placement, | ||||
Deletion, | ||||
Err, | ||||
} = ReactTypeOfSideEffect; | ||||
|
||||
function coerceRef(current: ?Fiber, element: ReactElement) { | ||||
|
@@ -1104,10 +1102,31 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |||
// not as a fragment. Nested arrays on the other hand will be treated as | ||||
// fragment nodes. Recursion happens at the normal flow. | ||||
|
||||
if (ReactFeatureFlags.disableNewFiberFeatures) { | ||||
const disableNewFiberFeatures = ReactFeatureFlags.disableNewFiberFeatures; | ||||
|
||||
// Handle object types | ||||
if (typeof newChild === 'object' && newChild !== null) { | ||||
// Support only the subset of return types that Stack supports. Treat | ||||
// everything else as empty, but log a warning. | ||||
if (typeof newChild === 'object' && newChild !== null) { | ||||
if (disableNewFiberFeatures) { | ||||
switch (newChild.$$typeof) { | ||||
case REACT_ELEMENT_TYPE: | ||||
return placeSingleChild(reconcileSingleElement( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
|
||||
case REACT_PORTAL_TYPE: | ||||
return placeSingleChild(reconcileSinglePortal( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
} | ||||
} else { | ||||
switch (newChild.$$typeof) { | ||||
case REACT_ELEMENT_TYPE: | ||||
return placeSingleChild(reconcileSingleElement( | ||||
|
@@ -1117,6 +1136,22 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |||
priority | ||||
)); | ||||
|
||||
case REACT_COROUTINE_TYPE: | ||||
return placeSingleChild(reconcileSingleCoroutine( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
|
||||
case REACT_YIELD_TYPE: | ||||
return placeSingleChild(reconcileSingleYield( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
|
||||
case REACT_PORTAL_TYPE: | ||||
return placeSingleChild(reconcileSinglePortal( | ||||
returnFiber, | ||||
|
@@ -1126,44 +1161,37 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |||
)); | ||||
} | ||||
} | ||||
} | ||||
|
||||
if (returnFiber.tag === HostRoot) { | ||||
// Top-level only accepts elements or portals | ||||
invariant( | ||||
// If the root has an error effect, this is an intentional unmount. | ||||
// Don't throw an error. | ||||
returnFiber.effectTag & Err, | ||||
'render(): Invalid component element.' | ||||
); | ||||
} else { | ||||
switch (returnFiber.tag) { | ||||
case ClassComponent: { | ||||
if (__DEV__) { | ||||
const instance = returnFiber.stateNode; | ||||
if (instance.render._isMockFunction) { | ||||
// We allow auto-mocks to proceed as if they're | ||||
// returning null. | ||||
break; | ||||
} | ||||
if (disableNewFiberFeatures) { | ||||
// The new child is not an element. If it's not null or false, | ||||
// and the return fiber is a composite component, throw an error. | ||||
switch (returnFiber.tag) { | ||||
case ClassComponent: { | ||||
if (__DEV__) { | ||||
const instance = returnFiber.stateNode; | ||||
if (instance.render._isMockFunction && typeof newChild === 'undefined') { | ||||
// We allow auto-mocks to proceed as if they're | ||||
// returning null. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you're really saying here is that they're allowed to return anything (including strings, arrays etc.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Looks like Stack only accepts
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||
break; | ||||
} | ||||
} | ||||
// Intentionally fall through to the next case, which handles both | ||||
// functions and classes | ||||
// eslint-disable-next-lined no-fallthrough | ||||
case FunctionalComponent: { | ||||
// Composites accept elements, portals, null, or false | ||||
const Component = returnFiber.type; | ||||
invariant( | ||||
newChild === null || newChild === false, | ||||
'%s.render(): A valid React element (or null) must be ' + | ||||
'returned. You may have returned undefined, an array or some ' + | ||||
'other invalid object.', | ||||
Component.displayName || Component.name || 'Component' | ||||
); | ||||
} | ||||
} | ||||
// Intentionally fall through to the next case, which handles both | ||||
// functions and classes | ||||
// eslint-disable-next-lined no-fallthrough | ||||
case FunctionalComponent: { | ||||
// Composites accept elements, portals, null, or false | ||||
const Component = returnFiber.type; | ||||
invariant( | ||||
newChild === null || newChild === false, | ||||
'%s(...): A valid React element (or null) must be ' + | ||||
'returned. You may have returned undefined, an array or some ' + | ||||
'other invalid object.', | ||||
Component.displayName || Component.name || 'Component' | ||||
); | ||||
} | ||||
} | ||||
return deleteRemainingChildren(returnFiber, currentFirstChild); | ||||
} | ||||
|
||||
if (typeof newChild === 'string' || typeof newChild === 'number') { | ||||
|
@@ -1175,65 +1203,29 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) { | |||
)); | ||||
} | ||||
|
||||
if (typeof newChild === 'object' && newChild !== null) { | ||||
switch (newChild.$$typeof) { | ||||
case REACT_ELEMENT_TYPE: | ||||
return placeSingleChild(reconcileSingleElement( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
|
||||
case REACT_COROUTINE_TYPE: | ||||
return placeSingleChild(reconcileSingleCoroutine( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
|
||||
case REACT_YIELD_TYPE: | ||||
return placeSingleChild(reconcileSingleYield( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
|
||||
case REACT_PORTAL_TYPE: | ||||
return placeSingleChild(reconcileSinglePortal( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
)); | ||||
} | ||||
|
||||
if (isArray(newChild)) { | ||||
return reconcileChildrenArray( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
); | ||||
} | ||||
if (isArray(newChild)) { | ||||
return reconcileChildrenArray( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
); | ||||
} | ||||
|
||||
if (getIteratorFn(newChild)) { | ||||
return reconcileChildrenIterator( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
); | ||||
} | ||||
if (getIteratorFn(newChild)) { | ||||
return reconcileChildrenIterator( | ||||
returnFiber, | ||||
currentFirstChild, | ||||
newChild, | ||||
priority | ||||
); | ||||
} | ||||
|
||||
if (typeof newChild === 'undefined') { | ||||
if (!disableNewFiberFeatures && typeof newChild === 'undefined') { | ||||
// If the new child is undefined, and the return fiber is a composite | ||||
// component, throw an error. If Fiber return types are disabled, | ||||
// we already threw above. | ||||
switch (returnFiber.tag) { | ||||
case HostRoot: | ||||
// TODO: Top-level render | ||||
break; | ||||
case ClassComponent: { | ||||
if (__DEV__) { | ||||
const instance = returnFiber.stateNode; | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unnecessary to fork this whole function now. Can't you just add this conditional down below behind a smaller
if (ReactFeatureFlags.disableNewFiberFeatures) {
instead of forking the whole function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forking the entire function was the only way I could get it down to a single check. But you're right that there's a lot of overlap and it's weird to fork the entire thing. I split it out into three checks instead.