MCPcopy
hub / github.com/vercel/next.js / withExecuteRevalidates

Function withExecuteRevalidates

packages/next/src/server/revalidation-utils.ts:6–26  ·  view source on GitHub ↗
(
  store: WorkStore | undefined,
  callback: () => Promise<T>
)

Source from the content-addressed store, hash-verified

4
5/** Run a callback, and execute any *new* revalidations added during its runtime. */
6export async function withExecuteRevalidates<T>(
7 store: WorkStore | undefined,
8 callback: () => Promise<T>
9): Promise<T> {
10 if (!store) {
11 return callback()
12 }
13 // If we executed any revalidates during the request, then we don't want to execute them again.
14 // save the state so we can check if anything changed after we're done running callbacks.
15 const savedRevalidationState = cloneRevalidationState(store)
16 try {
17 return await callback()
18 } finally {
19 // Check if we have any new revalidates, and if so, wait until they are all resolved.
20 const newRevalidates = diffRevalidationState(
21 savedRevalidationState,
22 cloneRevalidationState(store)
23 )
24 await executeRevalidates(store, newRevalidates)
25 }
26}
27
28type RevalidationState = Required<
29 Pick<

Callers 1

runCallbacksMethod · 0.90

Calls 4

cloneRevalidationStateFunction · 0.85
diffRevalidationStateFunction · 0.85
executeRevalidatesFunction · 0.85
callbackFunction · 0.50

Tested by

no test coverage detected