Skip to content
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

Add missing null checks to OffscreenInstance code #24846

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {Wakeable} from 'shared/ReactTypes';
import type {
OffscreenState,
OffscreenInstance,
OffscreenQueue,
} from './ReactFiberOffscreenComponent';
import type {HookFlags} from './ReactHookEffectTags';
import type {Cache} from './ReactFiberCacheComponent.new';
Expand Down Expand Up @@ -2877,8 +2878,8 @@ function commitPassiveMountOnFiber(

if (enableTransitionTracing) {
const isFallback = finishedWork.memoizedState;
const queue = (finishedWork.updateQueue: any);
const instance = finishedWork.stateNode;
const queue: OffscreenQueue = (finishedWork.updateQueue: any);
const instance: OffscreenInstance = finishedWork.stateNode;

if (queue !== null) {
if (isFallback) {
Expand All @@ -2896,7 +2897,11 @@ function commitPassiveMountOnFiber(
// Add all the transitions saved in the update queue during
// the render phase (ie the transitions associated with this boundary)
// into the transitions set.
prevTransitions.add(transition);
if (prevTransitions === null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PrevTransitions can't be null because we set it above to a new set if it is

if (transitions !== null && prevTransitions === null) {
    instance.transitions = prevTransitions = new Set();
}

// TODO: What if prevTransitions is null?
} else {
prevTransitions.add(transition);
}
});
}

Expand All @@ -2913,10 +2918,22 @@ function commitPassiveMountOnFiber(
// caused them
if (markerTransitions !== null) {
markerTransitions.forEach(transition => {
if (instance.transitions.has(transition)) {
instance.pendingMarkers.add(
markerInstance.pendingSuspenseBoundaries,
);
if (instance.transitions === null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instance.transitions also can't be null because we set it above if it is

// TODO: What if instance.transitions is null?
} else {
if (instance.transitions.has(transition)) {
if (
instance.pendingMarkers === null ||
markerInstance.pendingSuspenseBoundaries === null
) {
// TODO: What if instance.pendingMarkers is null?
// TODO: What if markerInstance.pendingSuspenseBoundaries is null?
} else {
instance.pendingMarkers.add(
markerInstance.pendingSuspenseBoundaries,
);
}
}
}
});
}
Expand Down
31 changes: 24 additions & 7 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {Wakeable} from 'shared/ReactTypes';
import type {
OffscreenState,
OffscreenInstance,
OffscreenQueue,
} from './ReactFiberOffscreenComponent';
import type {HookFlags} from './ReactHookEffectTags';
import type {Cache} from './ReactFiberCacheComponent.old';
Expand Down Expand Up @@ -2877,8 +2878,8 @@ function commitPassiveMountOnFiber(

if (enableTransitionTracing) {
const isFallback = finishedWork.memoizedState;
const queue = (finishedWork.updateQueue: any);
const instance = finishedWork.stateNode;
const queue: OffscreenQueue = (finishedWork.updateQueue: any);
const instance: OffscreenInstance = finishedWork.stateNode;

if (queue !== null) {
if (isFallback) {
Expand All @@ -2896,7 +2897,11 @@ function commitPassiveMountOnFiber(
// Add all the transitions saved in the update queue during
// the render phase (ie the transitions associated with this boundary)
// into the transitions set.
prevTransitions.add(transition);
if (prevTransitions === null) {
// TODO: What if prevTransitions is null?
} else {
prevTransitions.add(transition);
}
});
}

Expand All @@ -2913,10 +2918,22 @@ function commitPassiveMountOnFiber(
// caused them
if (markerTransitions !== null) {
markerTransitions.forEach(transition => {
if (instance.transitions.has(transition)) {
instance.pendingMarkers.add(
markerInstance.pendingSuspenseBoundaries,
);
if (instance.transitions === null) {
// TODO: What if instance.transitions is null?
} else {
if (instance.transitions.has(transition)) {
if (
instance.pendingMarkers === null ||
markerInstance.pendingSuspenseBoundaries === null
) {
// TODO: What if instance.pendingMarkers is null?
// TODO: What if markerInstance.pendingSuspenseBoundaries is null?
} else {
instance.pendingMarkers.add(
markerInstance.pendingSuspenseBoundaries,
);
}
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type BatchConfigTransition = {
export type TracingMarkerInstance = {|
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
transitions: Set<Transition> | null,
|} | null;
|};

export type PendingSuspenseBoundaries = Map<OffscreenInstance, SuspenseInfo>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type BatchConfigTransition = {
export type TracingMarkerInstance = {|
pendingSuspenseBoundaries: PendingSuspenseBoundaries | null,
transitions: Set<Transition> | null,
|} | null;
|};

export type PendingSuspenseBoundaries = Map<OffscreenInstance, SuspenseInfo>;

Expand Down