1
1
import type { Dispatch } from 'react'
2
- import React , { startTransition , use } from 'react'
2
+ import React , { use } from 'react'
3
3
import { isThenable } from '../../shared/lib/is-thenable'
4
4
import type { AppRouterActionQueue } from './app-router-instance'
5
5
import type {
@@ -19,20 +19,6 @@ export function dispatchAppRouterAction(action: ReducerActions) {
19
19
'Internal Next.js error: Router action dispatched before initialization.'
20
20
)
21
21
}
22
-
23
- if ( process . env . NODE_ENV !== 'production' ) {
24
- // In development, set an pending state on the DevTools indicator
25
- // whenever a router action is in progress. This is backed by useOptimistic,
26
- // so we don't need to set it back to false; it will be automatically reset
27
- // when the transition completes.
28
- const setDevRenderIndicatorPending =
29
- require ( './react-dev-overlay/utils/dev-indicator/dev-render-indicator' )
30
- . setDevRenderIndicatorPending as typeof import ( './react-dev-overlay/utils/dev-indicator/dev-render-indicator' ) . setDevRenderIndicatorPending
31
- startTransition ( ( ) => setDevRenderIndicatorPending ( ) )
32
- }
33
-
34
- // NOTE: This is wrapped in a startTransition internally, but to avoid a
35
- // refactor hazard we should consider wrapping it here instead.
36
22
dispatch ( action )
37
23
}
38
24
@@ -48,7 +34,22 @@ export function useActionQueue(
48
34
// Ideally, what we'd do instead is pass the state as a prop to root.render;
49
35
// this is conceptually how we're modeling the app router state, despite the
50
36
// weird implementation details.
51
- dispatch = ( action : ReducerActions ) => actionQueue . dispatch ( action , setState )
37
+ if ( process . env . NODE_ENV !== 'production' ) {
38
+ const useSyncDevRenderIndicator =
39
+ require ( './react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator' )
40
+ . useSyncDevRenderIndicator as typeof import ( './react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator' ) . useSyncDevRenderIndicator
41
+ // eslint-disable-next-line react-hooks/rules-of-hooks
42
+ const syncDevRenderIndicator = useSyncDevRenderIndicator ( )
43
+
44
+ dispatch = ( action : ReducerActions ) => {
45
+ syncDevRenderIndicator ( ( ) => {
46
+ actionQueue . dispatch ( action , setState )
47
+ } )
48
+ }
49
+ } else {
50
+ dispatch = ( action : ReducerActions ) =>
51
+ actionQueue . dispatch ( action , setState )
52
+ }
52
53
53
54
return isThenable ( state ) ? use ( state ) : state
54
55
}
0 commit comments