mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
When a server action triggers a redirect, we're incorrectly applying a refresh marker to the segment they were on, rather than the segment they were being redirected to. As a result, when revalidation occurs (via `revalidateX` or `router.refresh()`), the top-level segment would be replaced with data for an incorrect segment. For example, if triggering a redirect action from `/redirect` to `/`, the router state tree would save a reference to `/redirect`. The next time a refresh or revalidate happens, it'd refresh the segment data for `/redirect` instead of `/`. Fixes #64728 Closes NEXT-3156
30 lines
619 B
TypeScript
30 lines
619 B
TypeScript
'use server'
|
|
import { revalidatePath } from 'next/cache'
|
|
import { redirect } from 'next/navigation'
|
|
|
|
let 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('/')
|
|
}
|
|
|
|
export async function clearData() {
|
|
data = []
|
|
revalidatePath('/')
|
|
}
|