-
Notifications
You must be signed in to change notification settings - Fork 26k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parallel routes with server actions / revalidating router cache #59585
Merged
ztanner
merged 1 commit into
canary
from
12-13-fix_action_revalidation_within_a_parallel_slot
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-revalidation/app/@dialog/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-revalidation/app/@dialog/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return null | ||
} |
21 changes: 21 additions & 0 deletions
21
test/e2e/app-dir/parallel-routes-revalidation/app/@dialog/refresh-modal/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client' | ||
import Link from 'next/link' | ||
import { useRouter } from 'next/navigation' | ||
import React from 'react' | ||
|
||
export default function Page() { | ||
const router = useRouter() | ||
|
||
return ( | ||
<dialog open> | ||
<h1>Modal</h1> | ||
|
||
<br /> | ||
|
||
<button onClick={() => router.refresh()} id="refresh-router"> | ||
Refresh Router | ||
</button> | ||
<Link href="/">Close</Link> | ||
</dialog> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
test/e2e/app-dir/parallel-routes-revalidation/app/@dialog/revalidate-modal/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Link from 'next/link' | ||
|
||
import { revalidatePath } from 'next/cache' | ||
import { addData } from '../../actions' | ||
|
||
export default function Page() { | ||
async function createItem() { | ||
'use server' | ||
|
||
await addData(new Date().toISOString()) | ||
|
||
revalidatePath('/', 'layout') | ||
} | ||
|
||
return ( | ||
<dialog open> | ||
<h1>Modal</h1> | ||
|
||
<br /> | ||
|
||
<form action={createItem}> | ||
<button type="submit" className="button" id="create-entry"> | ||
Create New Item | ||
</button> | ||
</form> | ||
|
||
<Link href="/">Close</Link> | ||
</dialog> | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
test/e2e/app-dir/parallel-routes-revalidation/app/@interception/(.)redirect-modal/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { RedirectForm } from '../../components/RedirectForm' | ||
import { redirectAction } from '../../actions' | ||
|
||
export default function Page() { | ||
return ( | ||
<dialog open> | ||
<h1>Modal</h1> | ||
|
||
<br /> | ||
|
||
<RedirectForm action={redirectAction} /> | ||
</dialog> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-revalidation/app/@interception/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
23 changes: 23 additions & 0 deletions
23
test/e2e/app-dir/parallel-routes-revalidation/app/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use server' | ||
import { redirect } from 'next/navigation' | ||
|
||
const data = [] | ||
|
||
export async function addData(newData: string) { | ||
// sleep 1s | ||
await new Promise((resolve) => setTimeout(resolve, 1000)) | ||
data.push(newData) | ||
} | ||
|
||
export async function getData() { | ||
// sleep 1s | ||
await new Promise((resolve) => setTimeout(resolve, 1000)) | ||
return data | ||
} | ||
|
||
export async function redirectAction() { | ||
'use server' | ||
console.log('redirecting...') | ||
await new Promise((res) => setTimeout(res, 1000)) | ||
redirect('/') | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/parallel-routes-revalidation/app/components/RedirectForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use client' | ||
|
||
export function RedirectForm({ action }: { action: () => Promise<void> }) { | ||
return ( | ||
<form action={action}> | ||
<button type="submit" className="button" id="redirect"> | ||
Redirect to Home | ||
</button> | ||
</form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './page' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change in behavior to this file, just split it out of a ternary to better annotate with comments