@@ -19,7 +19,6 @@ import type {HookEffectTag} from './ReactHookEffectTags';
19
19
import type { SuspenseConfig } from './ReactFiberSuspenseConfig' ;
20
20
import type { ReactPriorityLevel } from './SchedulerWithReactIntegration' ;
21
21
22
- import * as Scheduler from 'scheduler' ;
23
22
import ReactSharedInternals from 'shared/ReactSharedInternals' ;
24
23
25
24
import { NoWork } from './ReactFiberExpirationTime' ;
@@ -53,7 +52,12 @@ import getComponentName from 'shared/getComponentName';
53
52
import is from 'shared/objectIs' ;
54
53
import { markWorkInProgressReceivedUpdate } from './ReactFiberBeginWork' ;
55
54
import { requestCurrentSuspenseConfig } from './ReactFiberSuspenseConfig' ;
56
- import { getCurrentPriorityLevel } from './SchedulerWithReactIntegration' ;
55
+ import {
56
+ UserBlockingPriority ,
57
+ NormalPriority ,
58
+ runWithPriority ,
59
+ getCurrentPriorityLevel ,
60
+ } from './SchedulerWithReactIntegration' ;
57
61
58
62
const { ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals ;
59
63
@@ -1135,15 +1139,13 @@ function mountDeferredValue<T>(
1135
1139
const [ prevValue , setValue ] = mountState ( value ) ;
1136
1140
mountEffect (
1137
1141
( ) => {
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
+ }
1147
1149
} ,
1148
1150
[ value , config ] ,
1149
1151
) ;
@@ -1157,65 +1159,62 @@ function updateDeferredValue<T>(
1157
1159
const [ prevValue , setValue ] = updateState ( value ) ;
1158
1160
updateEffect (
1159
1161
( ) => {
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
+ }
1169
1169
} ,
1170
1170
[ value , config ] ,
1171
1171
) ;
1172
1172
return prevValue ;
1173
1173
}
1174
1174
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
+
1175
1198
function mountTransition(
1176
1199
config: SuspenseConfig | void | null,
1177
1200
): [(() => void ) => void , boolean ] {
1178
1201
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 ] ;
1196
1207
}
1197
1208
1198
1209
function updateTransition(
1199
1210
config: SuspenseConfig | void | null,
1200
1211
): [(() => void ) => void , boolean ] {
1201
1212
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 ] ;
1219
1218
}
1220
1219
1221
1220
function dispatchAction< S , A > (
0 commit comments