Unverified Commit d8160e05 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Ensure unstable_cache revalidate option enables ISR (#57390)

Noticed that if you use `unstable_cache` it did not opt-in to ISR even though fetch() does opt-in. This ensures the prerender-manifest holds the revalidate value.
parent 509b88ae
import { maybePostpone } from '../../../client/components/maybe-postpone'
import type { import type {
StaticGenerationStore, StaticGenerationStore,
StaticGenerationAsyncStorage, StaticGenerationAsyncStorage,
...@@ -29,6 +30,23 @@ export function unstable_cache<T extends Callback>( ...@@ -29,6 +30,23 @@ export function unstable_cache<T extends Callback>(
const store: undefined | StaticGenerationStore = const store: undefined | StaticGenerationStore =
staticGenerationAsyncStorage?.getStore() staticGenerationAsyncStorage?.getStore()
if (store && typeof options.revalidate === 'number') {
// Revalidate 0 is a special case, it means opt-out of static generation.
if (options.revalidate === 0) {
maybePostpone(store, 'revalidate: 0')
// Set during dynamic rendering
store.revalidate = 0
// If revalidate was already set in the store before we should check if the new value is lower, set it to the lowest of the two.
} else if (typeof store.revalidate === 'number') {
if (store.revalidate > options.revalidate) {
store.revalidate = options.revalidate
}
// All other cases we set the value from the option.
} else {
store.revalidate = options.revalidate
}
}
const incrementalCache: const incrementalCache:
| import('../../lib/incremental-cache').IncrementalCache | import('../../lib/incremental-cache').IncrementalCache
| undefined = | undefined =
......
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