@@ -19,7 +19,6 @@ import type {HookEffectTag} from './ReactHookEffectTags';
1919import type { SuspenseConfig } from './ReactFiberSuspenseConfig' ;
2020import type { ReactPriorityLevel } from './SchedulerWithReactIntegration' ;
2121
22- import * as Scheduler from 'scheduler' ;
2322import ReactSharedInternals from 'shared/ReactSharedInternals' ;
2423
2524import { NoWork } from './ReactFiberExpirationTime' ;
@@ -53,7 +52,12 @@ import getComponentName from 'shared/getComponentName';
5352import is from 'shared/objectIs' ;
5453import { markWorkInProgressReceivedUpdate } from './ReactFiberBeginWork' ;
5554import { requestCurrentSuspenseConfig } from './ReactFiberSuspenseConfig' ;
56- import { getCurrentPriorityLevel } from './SchedulerWithReactIntegration' ;
55+ import {
56+ UserBlockingPriority ,
57+ NormalPriority ,
58+ runWithPriority ,
59+ getCurrentPriorityLevel ,
60+ } from './SchedulerWithReactIntegration' ;
5761
5862const { ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals ;
5963
@@ -1135,15 +1139,13 @@ function mountDeferredValue<T>(
11351139 const [ prevValue , setValue ] = mountState ( value ) ;
11361140 mountEffect (
11371141 ( ) => {
1138- Scheduler . unstable_next ( ( ) => {
1139- const previousConfig = ReactCurrentBatchConfig . suspense ;
1140- ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1141- try {
1142- setValue ( value ) ;
1143- } finally {
1144- ReactCurrentBatchConfig . suspense = previousConfig ;
1145- }
1146- } ) ;
1142+ const previousConfig = ReactCurrentBatchConfig . suspense ;
1143+ ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1144+ try {
1145+ setValue ( value ) ;
1146+ } finally {
1147+ ReactCurrentBatchConfig . suspense = previousConfig ;
1148+ }
11471149 } ,
11481150 [ value , config ] ,
11491151 ) ;
@@ -1157,65 +1159,62 @@ function updateDeferredValue<T>(
11571159 const [ prevValue , setValue ] = updateState ( value ) ;
11581160 updateEffect (
11591161 ( ) => {
1160- Scheduler . unstable_next ( ( ) => {
1161- const previousConfig = ReactCurrentBatchConfig . suspense ;
1162- ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1163- try {
1164- setValue ( value ) ;
1165- } finally {
1166- ReactCurrentBatchConfig . suspense = previousConfig ;
1167- }
1168- } ) ;
1162+ const previousConfig = ReactCurrentBatchConfig . suspense ;
1163+ ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1164+ try {
1165+ setValue ( value ) ;
1166+ } finally {
1167+ ReactCurrentBatchConfig . suspense = previousConfig ;
1168+ }
11691169 } ,
11701170 [ value , config ] ,
11711171 ) ;
11721172 return prevValue ;
11731173}
11741174
1175+ function startTransition(setPending, config, callback) {
1176+ const priorityLevel = getCurrentPriorityLevel ( ) ;
1177+ runWithPriority (
1178+ priorityLevel < UserBlockingPriority ? UserBlockingPriority : priorityLevel ,
1179+ ( ) => {
1180+ setPending ( true ) ;
1181+ } ,
1182+ ) ;
1183+ runWithPriority (
1184+ priorityLevel > NormalPriority ? NormalPriority : priorityLevel ,
1185+ ( ) => {
1186+ const previousConfig = ReactCurrentBatchConfig . suspense ;
1187+ ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1188+ try {
1189+ setPending ( false ) ;
1190+ callback ( ) ;
1191+ } finally {
1192+ ReactCurrentBatchConfig . suspense = previousConfig ;
1193+ }
1194+ } ,
1195+ ) ;
1196+ }
1197+
11751198function mountTransition(
11761199 config: SuspenseConfig | void | null,
11771200): [(() => void ) => void , boolean ] {
11781201 const [ isPending , setPending ] = mountState ( false ) ;
1179- const startTransition = mountCallback (
1180- callback => {
1181- setPending ( true ) ;
1182- Scheduler . unstable_next ( ( ) => {
1183- const previousConfig = ReactCurrentBatchConfig . suspense ;
1184- ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1185- try {
1186- setPending ( false ) ;
1187- callback ( ) ;
1188- } finally {
1189- ReactCurrentBatchConfig . suspense = previousConfig ;
1190- }
1191- } ) ;
1192- } ,
1193- [ config , isPending ] ,
1194- ) ;
1195- return [ startTransition , isPending ] ;
1202+ const start = mountCallback ( startTransition . bind ( null , setPending , config ) , [
1203+ setPending ,
1204+ config ,
1205+ ] ) ;
1206+ return [ start , isPending ] ;
11961207}
11971208
11981209function updateTransition(
11991210 config: SuspenseConfig | void | null,
12001211): [(() => void ) => void , boolean ] {
12011212 const [ isPending , setPending ] = updateState ( false ) ;
1202- const startTransition = updateCallback (
1203- callback => {
1204- setPending ( true ) ;
1205- Scheduler . unstable_next ( ( ) => {
1206- const previousConfig = ReactCurrentBatchConfig . suspense ;
1207- ReactCurrentBatchConfig . suspense = config === undefined ? null : config ;
1208- try {
1209- setPending ( false ) ;
1210- callback ( ) ;
1211- } finally {
1212- ReactCurrentBatchConfig . suspense = previousConfig ;
1213- }
1214- } ) ;
1215- } ,
1216- [ config , isPending ] ,
1217- ) ;
1218- return [ startTransition , isPending ] ;
1213+ const start = updateCallback ( startTransition . bind ( null , setPending , config ) , [
1214+ setPending ,
1215+ config ,
1216+ ] ) ;
1217+ return [ start , isPending ] ;
12191218}
12201219
12211220function dispatchAction< S , A > (
0 commit comments