-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land interleaved updates change in main fork (#20710)
* Land #20615 in main fork Includes change to interleaved updates. ``` yarn replace-fork ``` * Check deferRenderPhaseUpdateToNextBatch in test
- Loading branch information
Showing
9 changed files
with
219 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/react-reconciler/src/ReactFiberInterleavedUpdates.old.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {UpdateQueue as HookQueue} from './ReactFiberHooks.old'; | ||
import type {SharedQueue as ClassQueue} from './ReactUpdateQueue.old'; | ||
|
||
// An array of all update queues that received updates during the current | ||
// render. When this render exits, either because it finishes or because it is | ||
// interrupted, the interleaved updates will be transfered onto the main part | ||
// of the queue. | ||
let interleavedQueues: Array< | ||
HookQueue<any, any> | ClassQueue<any>, | ||
> | null = null; | ||
|
||
export function pushInterleavedQueue( | ||
queue: HookQueue<any, any> | ClassQueue<any>, | ||
) { | ||
if (interleavedQueues === null) { | ||
interleavedQueues = [queue]; | ||
} else { | ||
interleavedQueues.push(queue); | ||
} | ||
} | ||
|
||
export function enqueueInterleavedUpdates() { | ||
// Transfer the interleaved updates onto the main queue. Each queue has a | ||
// `pending` field and an `interleaved` field. When they are not null, they | ||
// point to the last node in a circular linked list. We need to append the | ||
// interleaved list to the end of the pending list by joining them into a | ||
// single, circular list. | ||
if (interleavedQueues !== null) { | ||
for (let i = 0; i < interleavedQueues.length; i++) { | ||
const queue = interleavedQueues[i]; | ||
const lastInterleavedUpdate = queue.interleaved; | ||
if (lastInterleavedUpdate !== null) { | ||
queue.interleaved = null; | ||
const firstInterleavedUpdate = lastInterleavedUpdate.next; | ||
const lastPendingUpdate = queue.pending; | ||
if (lastPendingUpdate !== null) { | ||
const firstPendingUpdate = lastPendingUpdate.next; | ||
lastPendingUpdate.next = (firstInterleavedUpdate: any); | ||
lastInterleavedUpdate.next = (firstPendingUpdate: any); | ||
} | ||
queue.pending = (lastInterleavedUpdate: any); | ||
} | ||
} | ||
interleavedQueues = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.