Skip to content
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
13 changes: 13 additions & 0 deletions packages/react-reconciler/src/ReactFiberConcurrentUpdates.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import {NoFlags, Placement, Hydrating} from './ReactFiberFlags';
import {HostRoot, OffscreenComponent} from './ReactWorkTags';
import {OffscreenVisible} from './ReactFiberOffscreenComponent';
import {getWorkInProgressRoot} from './ReactFiberWorkLoop.new';

export type ConcurrentUpdate = {
next: ConcurrentUpdate,
Expand Down Expand Up @@ -139,6 +140,18 @@ export function enqueueConcurrentHookUpdateAndEagerlyBailout<S, A>(
const concurrentQueue: ConcurrentQueue = (queue: any);
const concurrentUpdate: ConcurrentUpdate = (update: any);
enqueueUpdate(fiber, concurrentQueue, concurrentUpdate, lane);

// Usually we can rely on the upcoming render phase to process the concurrent
// queue. However, since this is a bail out, we're not scheduling any work
// here. So the update we just queued will leak until something else happens
// to schedule work (if ever).
//
// Check if we're currently in the middle of rendering a tree, and if not,
// process the queue immediately to prevent a leak.
const isConcurrentlyRendering = getWorkInProgressRoot() !== null;
if (!isConcurrentlyRendering) {
finishQueueingConcurrentUpdates();
}
}

export function enqueueConcurrentClassUpdate<State>(
Expand Down
13 changes: 13 additions & 0 deletions packages/react-reconciler/src/ReactFiberConcurrentUpdates.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import {NoFlags, Placement, Hydrating} from './ReactFiberFlags';
import {HostRoot, OffscreenComponent} from './ReactWorkTags';
import {OffscreenVisible} from './ReactFiberOffscreenComponent';
import {getWorkInProgressRoot} from './ReactFiberWorkLoop.old';

export type ConcurrentUpdate = {
next: ConcurrentUpdate,
Expand Down Expand Up @@ -139,6 +140,18 @@ export function enqueueConcurrentHookUpdateAndEagerlyBailout<S, A>(
const concurrentQueue: ConcurrentQueue = (queue: any);
const concurrentUpdate: ConcurrentUpdate = (update: any);
enqueueUpdate(fiber, concurrentQueue, concurrentUpdate, lane);

// Usually we can rely on the upcoming render phase to process the concurrent
// queue. However, since this is a bail out, we're not scheduling any work
// here. So the update we just queued will leak until something else happens
// to schedule work (if ever).
//
// Check if we're currently in the middle of rendering a tree, and if not,
// process the queue immediately to prevent a leak.
const isConcurrentlyRendering = getWorkInProgressRoot() !== null;
if (!isConcurrentlyRendering) {
finishQueueingConcurrentUpdates();
}
}

export function enqueueConcurrentClassUpdate<State>(
Expand Down
6 changes: 6 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,9 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) {
workInProgressRoot = null;
workInProgressRootRenderLanes = NoLanes;

// It's safe to process the queue now that the render phase is complete.
finishQueueingConcurrentUpdates();

return workInProgressRootExitStatus;
}

Expand Down Expand Up @@ -2017,6 +2020,9 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
workInProgressRoot = null;
workInProgressRootRenderLanes = NoLanes;

// It's safe to process the queue now that the render phase is complete.
finishQueueingConcurrentUpdates();

// Return the final exit status.
return workInProgressRootExitStatus;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,9 @@ function renderRootSync(root: FiberRoot, lanes: Lanes) {
workInProgressRoot = null;
workInProgressRootRenderLanes = NoLanes;

// It's safe to process the queue now that the render phase is complete.
finishQueueingConcurrentUpdates();

return workInProgressRootExitStatus;
}

Expand Down Expand Up @@ -2017,6 +2020,9 @@ function renderRootConcurrent(root: FiberRoot, lanes: Lanes) {
workInProgressRoot = null;
workInProgressRootRenderLanes = NoLanes;

// It's safe to process the queue now that the render phase is complete.
finishQueueingConcurrentUpdates();

// Return the final exit status.
return workInProgressRootExitStatus;
}
Expand Down