Skip to content

Commit 66b29c9

Browse files
committed
Remove obsolete update of implicit tags expiration after server action
With the change in #76885, we don't need to update the expiration date of implicit tags anymore at the end of a request to ensure no stale data is used after `revalidatePath` was called in a server action. This PR is covered by the existing tests, e.g. `use-cache should revalidate caches after redirect`.
1 parent c1ae827 commit 66b29c9

File tree

4 files changed

+6
-56
lines changed

4 files changed

+6
-56
lines changed

packages/next/src/server/app-render/action-handler.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,6 @@ export async function handleAction({
517517

518518
requestStore.phase = 'action'
519519

520-
const resolvePendingRevalidations = async () =>
521-
workUnitAsyncStorage.run(requestStore, () => executeRevalidates(workStore))
522-
523520
// When running actions the default is no-store, you can still `cache: 'force-cache'`
524521
workStore.fetchCache = 'default-no-store'
525522

@@ -571,7 +568,7 @@ export async function handleAction({
571568

572569
if (isFetchAction) {
573570
res.statusCode = 500
574-
await resolvePendingRevalidations()
571+
await executeRevalidates(workStore)
575572

576573
const promise = Promise.reject(error)
577574
try {
@@ -926,7 +923,7 @@ export async function handleAction({
926923

927924
// For form actions, we need to continue rendering the page.
928925
if (isFetchAction) {
929-
await resolvePendingRevalidations()
926+
await executeRevalidates(workStore)
930927
addRevalidationHeader(res, { workStore, requestStore })
931928

932929
actionResult = await finalizeAndGenerateFlight(req, ctx, requestStore, {
@@ -948,7 +945,7 @@ export async function handleAction({
948945
const redirectUrl = getURLFromRedirectError(err)
949946
const redirectType = getRedirectTypeFromError(err)
950947

951-
await resolvePendingRevalidations()
948+
await executeRevalidates(workStore)
952949
addRevalidationHeader(res, { workStore, requestStore })
953950

954951
// if it's a fetch action, we'll set the status code for logging/debugging purposes
@@ -978,7 +975,7 @@ export async function handleAction({
978975
} else if (isHTTPAccessFallbackError(err)) {
979976
res.statusCode = getAccessFallbackHTTPStatus(err)
980977

981-
await resolvePendingRevalidations()
978+
await executeRevalidates(workStore)
982979
addRevalidationHeader(res, { workStore, requestStore })
983980

984981
if (isFetchAction) {
@@ -1008,7 +1005,7 @@ export async function handleAction({
10081005

10091006
if (isFetchAction) {
10101007
res.statusCode = 500
1011-
await resolvePendingRevalidations()
1008+
await executeRevalidates(workStore)
10121009
const promise = Promise.reject(err)
10131010
try {
10141011
// we need to await the promise to trigger the rejection early

packages/next/src/server/lib/implicit-tags.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@ async function getImplicitTagsExpiration(tags: string[]): Promise<number> {
7171
return expiration
7272
}
7373

74-
/**
75-
* Fetches a new expiration value for the given `implicitTags`, and mutates its
76-
* `expiration` property.
77-
*/
78-
export async function updateImplicitTagsExpiration(
79-
implicitTags: ImplicitTags
80-
): Promise<void> {
81-
implicitTags.expiration = await getImplicitTagsExpiration(implicitTags.tags)
82-
}
83-
8474
export async function getImplicitTags(
8575
page: string,
8676
url: {

packages/next/src/server/revalidation-utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import type { WorkStore } from './app-render/work-async-storage.external'
2-
import { workUnitAsyncStorage } from './app-render/work-unit-async-storage.external'
3-
import { updateImplicitTagsExpiration } from './lib/implicit-tags'
42
import type { IncrementalCache } from './lib/incremental-cache'
53
import { getCacheHandlers } from './use-cache/handlers'
64

@@ -89,16 +87,6 @@ async function revalidateTags(
8987
}
9088

9189
await Promise.all(promises)
92-
93-
const workUnitStore = workUnitAsyncStorage.getStore()
94-
95-
if (workUnitStore?.implicitTags) {
96-
const tagsSet = new Set(tags)
97-
98-
if (workUnitStore.implicitTags.tags.some((tag) => tagsSet.has(tag))) {
99-
await updateImplicitTagsExpiration(workUnitStore.implicitTags)
100-
}
101-
}
10290
}
10391

10492
export async function executeRevalidates(

test/e2e/app-dir/use-cache-custom-handler/use-cache-custom-handler.test.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('use-cache-custom-handler', () => {
147147
})
148148
})
149149

150-
it('should not call getExpiration again after an action if only explicit tags were revalidated', async () => {
150+
it('should not call getExpiration again after an action', async () => {
151151
const browser = await next.browser(`/`)
152152

153153
await retry(async () => {
@@ -171,29 +171,4 @@ describe('use-cache-custom-handler', () => {
171171
)
172172
})
173173
})
174-
175-
it('should call getExpiration again after an action if implicit tags were revalidated', async () => {
176-
const browser = await next.browser(`/`)
177-
178-
await retry(async () => {
179-
const cliOutput = next.cliOutput.slice(outputIndex)
180-
expect(cliOutput).toInclude('ModernCustomCacheHandler::getExpiration')
181-
})
182-
183-
outputIndex = next.cliOutput.length
184-
185-
await browser.elementById('revalidate-path').click()
186-
187-
await retry(async () => {
188-
const cliOutput = next.cliOutput.slice(outputIndex)
189-
expect(cliOutput).toIncludeRepeated(
190-
'ModernCustomCacheHandler::expireTags',
191-
1
192-
)
193-
expect(cliOutput).toIncludeRepeated(
194-
'ModernCustomCacheHandler::getExpiration',
195-
2
196-
)
197-
})
198-
})
199174
})

0 commit comments

Comments
 (0)