Unverified Commit 5b6b225b authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Remove obsolete update of implicit tags expiration after server action (#77595)

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`.
parent 4c7a31a7
...@@ -517,9 +517,6 @@ export async function handleAction({ ...@@ -517,9 +517,6 @@ export async function handleAction({
requestStore.phase = 'action' requestStore.phase = 'action'
const resolvePendingRevalidations = async () =>
workUnitAsyncStorage.run(requestStore, () => executeRevalidates(workStore))
// When running actions the default is no-store, you can still `cache: 'force-cache'` // When running actions the default is no-store, you can still `cache: 'force-cache'`
workStore.fetchCache = 'default-no-store' workStore.fetchCache = 'default-no-store'
...@@ -571,7 +568,7 @@ export async function handleAction({ ...@@ -571,7 +568,7 @@ export async function handleAction({
if (isFetchAction) { if (isFetchAction) {
res.statusCode = 500 res.statusCode = 500
await resolvePendingRevalidations() await executeRevalidates(workStore)
const promise = Promise.reject(error) const promise = Promise.reject(error)
try { try {
...@@ -926,7 +923,7 @@ export async function handleAction({ ...@@ -926,7 +923,7 @@ export async function handleAction({
// For form actions, we need to continue rendering the page. // For form actions, we need to continue rendering the page.
if (isFetchAction) { if (isFetchAction) {
await resolvePendingRevalidations() await executeRevalidates(workStore)
addRevalidationHeader(res, { workStore, requestStore }) addRevalidationHeader(res, { workStore, requestStore })
actionResult = await finalizeAndGenerateFlight(req, ctx, requestStore, { actionResult = await finalizeAndGenerateFlight(req, ctx, requestStore, {
...@@ -948,7 +945,7 @@ export async function handleAction({ ...@@ -948,7 +945,7 @@ export async function handleAction({
const redirectUrl = getURLFromRedirectError(err) const redirectUrl = getURLFromRedirectError(err)
const redirectType = getRedirectTypeFromError(err) const redirectType = getRedirectTypeFromError(err)
await resolvePendingRevalidations() await executeRevalidates(workStore)
addRevalidationHeader(res, { workStore, requestStore }) addRevalidationHeader(res, { workStore, requestStore })
// if it's a fetch action, we'll set the status code for logging/debugging purposes // if it's a fetch action, we'll set the status code for logging/debugging purposes
...@@ -978,7 +975,7 @@ export async function handleAction({ ...@@ -978,7 +975,7 @@ export async function handleAction({
} else if (isHTTPAccessFallbackError(err)) { } else if (isHTTPAccessFallbackError(err)) {
res.statusCode = getAccessFallbackHTTPStatus(err) res.statusCode = getAccessFallbackHTTPStatus(err)
await resolvePendingRevalidations() await executeRevalidates(workStore)
addRevalidationHeader(res, { workStore, requestStore }) addRevalidationHeader(res, { workStore, requestStore })
if (isFetchAction) { if (isFetchAction) {
...@@ -1008,7 +1005,7 @@ export async function handleAction({ ...@@ -1008,7 +1005,7 @@ export async function handleAction({
if (isFetchAction) { if (isFetchAction) {
res.statusCode = 500 res.statusCode = 500
await resolvePendingRevalidations() await executeRevalidates(workStore)
const promise = Promise.reject(err) const promise = Promise.reject(err)
try { try {
// we need to await the promise to trigger the rejection early // we need to await the promise to trigger the rejection early
......
...@@ -13,7 +13,7 @@ export interface ImplicitTags { ...@@ -13,7 +13,7 @@ export interface ImplicitTags {
* implicit tags' expiration is stored in the work unit store, and used to * implicit tags' expiration is stored in the work unit store, and used to
* compare with a cache entry's timestamp. * compare with a cache entry's timestamp.
*/ */
expiration: number readonly expiration: number
} }
const getDerivedTags = (pathname: string): string[] => { const getDerivedTags = (pathname: string): string[] => {
...@@ -71,16 +71,6 @@ async function getImplicitTagsExpiration(tags: string[]): Promise<number> { ...@@ -71,16 +71,6 @@ async function getImplicitTagsExpiration(tags: string[]): Promise<number> {
return expiration return expiration
} }
/**
* Fetches a new expiration value for the given `implicitTags`, and mutates its
* `expiration` property.
*/
export async function updateImplicitTagsExpiration(
implicitTags: ImplicitTags
): Promise<void> {
implicitTags.expiration = await getImplicitTagsExpiration(implicitTags.tags)
}
export async function getImplicitTags( export async function getImplicitTags(
page: string, page: string,
url: { url: {
......
import type { WorkStore } from './app-render/work-async-storage.external' import type { WorkStore } from './app-render/work-async-storage.external'
import { workUnitAsyncStorage } from './app-render/work-unit-async-storage.external'
import { updateImplicitTagsExpiration } from './lib/implicit-tags'
import type { IncrementalCache } from './lib/incremental-cache' import type { IncrementalCache } from './lib/incremental-cache'
import { getCacheHandlers } from './use-cache/handlers' import { getCacheHandlers } from './use-cache/handlers'
...@@ -89,16 +87,6 @@ async function revalidateTags( ...@@ -89,16 +87,6 @@ async function revalidateTags(
} }
await Promise.all(promises) await Promise.all(promises)
const workUnitStore = workUnitAsyncStorage.getStore()
if (workUnitStore?.implicitTags) {
const tagsSet = new Set(tags)
if (workUnitStore.implicitTags.tags.some((tag) => tagsSet.has(tag))) {
await updateImplicitTagsExpiration(workUnitStore.implicitTags)
}
}
} }
export async function executeRevalidates( export async function executeRevalidates(
......
...@@ -147,7 +147,7 @@ describe('use-cache-custom-handler', () => { ...@@ -147,7 +147,7 @@ describe('use-cache-custom-handler', () => {
}) })
}) })
it('should not call getExpiration again after an action if only explicit tags were revalidated', async () => { it('should not call getExpiration again after an action', async () => {
const browser = await next.browser(`/`) const browser = await next.browser(`/`)
await retry(async () => { await retry(async () => {
...@@ -171,29 +171,4 @@ describe('use-cache-custom-handler', () => { ...@@ -171,29 +171,4 @@ describe('use-cache-custom-handler', () => {
) )
}) })
}) })
it('should call getExpiration again after an action if implicit tags were revalidated', async () => {
const browser = await next.browser(`/`)
await retry(async () => {
const cliOutput = next.cliOutput.slice(outputIndex)
expect(cliOutput).toInclude('ModernCustomCacheHandler::getExpiration')
})
outputIndex = next.cliOutput.length
await browser.elementById('revalidate-path').click()
await retry(async () => {
const cliOutput = next.cliOutput.slice(outputIndex)
expect(cliOutput).toIncludeRepeated(
'ModernCustomCacheHandler::expireTags',
1
)
expect(cliOutput).toIncludeRepeated(
'ModernCustomCacheHandler::getExpiration',
2
)
})
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment