@@ -26,7 +26,7 @@ export type AppRouterActionQueue = {
26
26
export type ActionQueueNode = {
27
27
payload : ReducerActions
28
28
next : ActionQueueNode | null
29
- resolve : ( value : PromiseLike < AppRouterState > | AppRouterState ) => void
29
+ resolve : ( value : ReducerState ) => void
30
30
reject : ( err : Error ) => void
31
31
discarded ?: boolean
32
32
}
@@ -115,14 +115,26 @@ function dispatchAction(
115
115
setState : DispatchStatePromise
116
116
) {
117
117
let resolvers : {
118
- resolve : ( value : AppRouterState | PromiseLike < AppRouterState > ) => void
118
+ resolve : ( value : ReducerState ) => void
119
119
reject : ( reason : any ) => void
120
- }
120
+ } = { resolve : setState , reject : ( ) => { } }
121
+
122
+ // most of the action types are async with the exception of restore
123
+ // it's important that restore is handled quickly since it's fired on the popstate event
124
+ // and we don't want to add any delay on a back/forward nav
125
+ // this only creates a promise for the async actions
126
+ if ( payload . type !== 'restore' ) {
127
+ // Create the promise and assign the resolvers to the object.
128
+ const deferredPromise = new Promise < AppRouterState > ( ( resolve , reject ) => {
129
+ resolvers = { resolve, reject }
130
+ } )
121
131
122
- // Create the promise and assign the resolvers to the object.
123
- const deferredPromise = new Promise < AppRouterState > ( ( resolve , reject ) => {
124
- resolvers = { resolve, reject }
125
- } )
132
+ startTransition ( ( ) => {
133
+ // we immediately notify React of the pending promise -- the resolver is attached to the action node
134
+ // and will be called when the associated action promise resolves
135
+ setState ( deferredPromise )
136
+ } )
137
+ }
126
138
127
139
const newAction : ActionQueueNode = {
128
140
payload,
@@ -131,12 +143,6 @@ function dispatchAction(
131
143
reject : resolvers ! . reject ,
132
144
}
133
145
134
- startTransition ( ( ) => {
135
- // we immediately notify React of the pending promise -- the resolver is attached to the action node
136
- // and will be called when the associated action promise resolves
137
- setState ( deferredPromise )
138
- } )
139
-
140
146
// Check if the queue is empty
141
147
if ( actionQueue . pending === null ) {
142
148
// The queue is empty, so add the action and start it immediately
0 commit comments