File tree Expand file tree Collapse file tree 5 files changed +78
-14
lines changed Expand file tree Collapse file tree 5 files changed +78
-14
lines changed Original file line number Diff line number Diff line change @@ -437,10 +437,10 @@ function InnerLayoutRouter({
437
437
// It's important that we mark this as resolved, in case this branch is replayed, we don't want to continously re-apply
438
438
// the patch to the tree.
439
439
childNode . lazyDataResolved = true
440
- }
441
440
442
- // Suspend infinitely as `changeByServerResponse` will cause a different part of the tree to be rendered.
443
- use ( unresolvedThenable ) as never
441
+ // Suspend infinitely as `changeByServerResponse` will cause a different part of the tree to be rendered.
442
+ use ( unresolvedThenable ) as never
443
+ }
444
444
}
445
445
446
446
// If we get to this point, then we know we have something we can render.
Original file line number Diff line number Diff line change @@ -48,6 +48,18 @@ function runRemainingActions(
48
48
action : actionQueue . pending ,
49
49
setState,
50
50
} )
51
+ } else {
52
+ // No more actions are pending, check if a refresh is needed
53
+ if ( actionQueue . needsRefresh ) {
54
+ actionQueue . needsRefresh = false
55
+ actionQueue . dispatch (
56
+ {
57
+ type : ACTION_REFRESH ,
58
+ origin : window . location . origin ,
59
+ } ,
60
+ setState
61
+ )
62
+ }
51
63
}
52
64
}
53
65
}
@@ -75,17 +87,7 @@ async function runAction({
75
87
function handleResult ( nextState : AppRouterState ) {
76
88
// if we discarded this action, the state should also be discarded
77
89
if ( action . discarded ) {
78
- // if a refresh is needed, we only want to trigger it once the action queue is empty
79
- if ( actionQueue . needsRefresh && actionQueue . pending === null ) {
80
- actionQueue . needsRefresh = false
81
- actionQueue . dispatch (
82
- {
83
- type : ACTION_REFRESH ,
84
- origin : window . location . origin ,
85
- } ,
86
- setState
87
- )
88
- }
90
+ console . log ( 'discarded an action' )
89
91
return
90
92
}
91
93
Original file line number Diff line number Diff line change @@ -371,6 +371,31 @@ createNextDescribe(
371
371
} , 'success' )
372
372
} )
373
373
374
+ it ( 'should trigger a refresh for a server action that also dispatches a navigation event' , async ( ) => {
375
+ let browser = await next . browser ( '/revalidate' )
376
+ let initialJustPutit = await browser . elementById ( 'justputit' ) . text ( )
377
+
378
+ // this triggers a revalidate + redirect in a client component
379
+ await browser . elementById ( 'redirect-revalidate-client' ) . click ( )
380
+ await retry ( async ( ) => {
381
+ const newJustPutIt = await browser . elementById ( 'justputit' ) . text ( )
382
+ expect ( newJustPutIt ) . not . toBe ( initialJustPutit )
383
+
384
+ expect ( await browser . url ( ) ) . toBe ( `${ next . url } /revalidate?foo=bar` )
385
+ } )
386
+
387
+ // this triggers a revalidate + redirect in a server component
388
+ browser = await next . browser ( '/revalidate' )
389
+ initialJustPutit = await browser . elementById ( 'justputit' ) . text ( )
390
+ await browser . elementById ( 'redirect-revalidate' ) . click ( )
391
+ await retry ( async ( ) => {
392
+ const newJustPutIt = await browser . elementById ( 'justputit' ) . text ( )
393
+ expect ( newJustPutIt ) . not . toBe ( initialJustPutit )
394
+
395
+ expect ( await browser . url ( ) ) . toBe ( `${ next . url } /revalidate?foo=bar` )
396
+ } )
397
+ } )
398
+
374
399
it ( 'should support next/dynamic with ssr: false' , async ( ) => {
375
400
const browser = await next . browser ( '/dynamic-csr' )
376
401
Original file line number Diff line number Diff line change
1
+ 'use client'
2
+
3
+ import { useRouter } from 'next/navigation'
4
+
5
+ export default function RedirectClientComponent ( { action } ) {
6
+ const router = useRouter ( )
7
+ return (
8
+ < button
9
+ id = "redirect-revalidate-client"
10
+ onClick = { async ( ) => {
11
+ await action ( )
12
+ router . push ( '/revalidate?foo=bar' )
13
+ } }
14
+ >
15
+ redirect + revalidate (client component)
16
+ </ button >
17
+ )
18
+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { redirect } from 'next/navigation'
7
7
import Link from 'next/link'
8
8
9
9
import { cookies } from 'next/headers'
10
+ import RedirectClientComponent from './client'
10
11
11
12
export default async function Page ( ) {
12
13
const data = await fetch (
@@ -133,6 +134,24 @@ export default async function Page() {
133
134
redirect
134
135
</ button >
135
136
</ form >
137
+ < form >
138
+ < button
139
+ id = "redirect-revalidate"
140
+ formAction = { async ( ) => {
141
+ 'use server'
142
+ revalidateTag ( 'justputit' )
143
+ redirect ( '/revalidate?foo=bar' )
144
+ } }
145
+ >
146
+ redirect + revalidate
147
+ </ button >
148
+ </ form >
149
+ < RedirectClientComponent
150
+ action = { async ( ) => {
151
+ 'use server'
152
+ revalidateTag ( 'justputit' )
153
+ } }
154
+ />
136
155
</ >
137
156
)
138
157
}
You can’t perform that action at this time.
0 commit comments