-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fiber] Move updatePriority tracking to renderers (#28751)
Currently updatePriority is tracked in the reconciler. `flushSync` is going to be implemented reconciler agnostic soon and we need to move the tracking of this state to the renderer and out of reconciler. This change implements new renderer bin dings for getCurrentUpdatePriority and setCurrentUpdatePriority. I was originally going to have the getter also do the event priority defaulting using window.event so we eliminate getCur rentEventPriority but this makes all the callsites where we store the true current updatePriority on the stack harder to work with so for now they remain separate. I also moved runWithPriority to the renderer since it really belongs whereever the state is being managed and it is only currently exposed in the DOM renderer. Additionally the current update priority is not stored on ReactDOMSharedInternals. While not particularly meaningful in this change it opens the door to implementing `flushSync` outside of the reconciler
- Loading branch information
1 parent
6715bb1
commit ce4fe7d
Showing
22 changed files
with
217 additions
and
98 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
55 changes: 55 additions & 0 deletions
55
packages/react-dom-bindings/src/client/ReactDOMUpdatePriority.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) Meta Platforms, Inc. and 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 {EventPriority} from 'react-reconciler/src/ReactEventPriorities'; | ||
|
||
import {getEventPriority} from '../events/ReactDOMEventListener'; | ||
import { | ||
NoEventPriority, | ||
DefaultEventPriority, | ||
} from 'react-reconciler/src/ReactEventPriorities'; | ||
|
||
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals'; | ||
|
||
export function setCurrentUpdatePriority( | ||
newPriority: EventPriority, | ||
// Closure will consistently not inline this function when it has arity 1 | ||
// however when it has arity 2 even if the second arg is omitted at every | ||
// callsite it seems to inline it even when the internal length of the function | ||
// is much longer. I hope this is consistent enough to rely on across builds | ||
IntentionallyUnusedArgument?: empty, | ||
): void { | ||
ReactDOMSharedInternals.up = newPriority; | ||
} | ||
|
||
export function getCurrentUpdatePriority(): EventPriority { | ||
return ReactDOMSharedInternals.up; | ||
} | ||
|
||
export function resolveUpdatePriority(): EventPriority { | ||
const updatePriority = ReactDOMSharedInternals.up; | ||
if (updatePriority !== NoEventPriority) { | ||
return updatePriority; | ||
} | ||
const currentEvent = window.event; | ||
if (currentEvent === undefined) { | ||
return DefaultEventPriority; | ||
} | ||
return getEventPriority(currentEvent.type); | ||
} | ||
|
||
export function runWithPriority<T>(priority: EventPriority, fn: () => T): T { | ||
const previousPriority = getCurrentUpdatePriority(); | ||
try { | ||
setCurrentUpdatePriority(priority); | ||
return fn(); | ||
} finally { | ||
setCurrentUpdatePriority(previousPriority); | ||
} | ||
} |
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
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.