Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Jun 6, 2023
1 parent c1221a5 commit a4bab8f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ export function serverActionReducer(
// cache is updated with the action's flight data again.
if (revalidatedParts.tag) {
// Invalidate everything if the tag is set.
state.prefetchCache.clear()
action.mutable.prefetchCache = new Map()
} else if (revalidatedParts.paths.length > 0) {
// Invalidate all subtrees that are below the revalidated paths, and invalidate
// all the prefetch cache.
// TODO-APP: Currently the prefetch cache doesn't have subtree information,
// so we need to invalidate the entire cache if a path was revalidated.
state.prefetchCache.clear()
action.mutable.prefetchCache = new Map()
}

if (redirectLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface ServerActionMutable {
serverActionApplied?: boolean
previousTree?: FlightRouterState
previousUrl?: string
prefetchCache?: AppRouterState['prefetchCache']
}

/**
Expand Down
15 changes: 7 additions & 8 deletions packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ function fetchIPv4v6(

async function addRevalidationHeader(
res: ServerResponse,
revalidatedTags: string[] = []
staticGenerationStore: StaticGenerationStore
) {
await Promise.all(staticGenerationStore.pendingRevalidates || [])

// If a tag was revalidated, the client router needs to invalidate all the
// client router cache as they may be stale. And if a path was revalidated, the
// client needs to invalidate all subtrees below that path.
Expand All @@ -145,7 +147,7 @@ async function addRevalidationHeader(

res.setHeader(
'x-action-revalidated',
JSON.stringify([revalidatedTags.length ? 1 : 0, []])
JSON.stringify([staticGenerationStore.revalidatedTags?.length ? 1 : 0, []])
)
}

Expand Down Expand Up @@ -372,8 +374,7 @@ export async function handleAction({

// For form actions, we need to continue rendering the page.
if (isFetchAction) {
await Promise.all(staticGenerationStore.pendingRevalidates || [])
addRevalidationHeader(res, staticGenerationStore.revalidatedTags)
await addRevalidationHeader(res, staticGenerationStore)

actionResult = await generateFlight({
actionResult: Promise.resolve(returnVal),
Expand All @@ -390,8 +391,7 @@ export async function handleAction({

// if it's a fetch action, we don't want to mess with the status code
// and we'll handle it on the client router
await Promise.all(staticGenerationStore.pendingRevalidates || [])
addRevalidationHeader(res, staticGenerationStore.revalidatedTags)
await addRevalidationHeader(res, staticGenerationStore)

if (isFetchAction) {
return createRedirectRenderResult(
Expand All @@ -418,8 +418,7 @@ export async function handleAction({
} else if (isNotFoundError(err)) {
res.statusCode = 404

await Promise.all(staticGenerationStore.pendingRevalidates || [])
addRevalidationHeader(res, staticGenerationStore.revalidatedTags)
await addRevalidationHeader(res, staticGenerationStore)

if (isFetchAction) {
const promise = Promise.reject(err)
Expand Down

0 comments on commit a4bab8f

Please sign in to comment.