Skip to content

Comments

Use provided waitUntil for pending revalidates (#74164)#6

Open
MitchLewis930 wants to merge 1 commit intopr_036_beforefrom
pr_036_after
Open

Use provided waitUntil for pending revalidates (#74164)#6
MitchLewis930 wants to merge 1 commit intopr_036_beforefrom
pr_036_after

Conversation

@MitchLewis930
Copy link

PR_036

Currently we are using `pendingWaitUntil` on `renderOpts` to handle
pending revalidations (fetch updates and revalidate tag calls). This
uses our old strategy of `waitUntil` inside of `sendResponse` which just
keeps the stream open until the promise resolves. This isn't ideal if we
have a proper waitUntil strategy provided so this updates to ensure we
use that instead if available.

Also adds some debug logs so we can track when this pending revalidates
promise is resolved.
@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 01:04
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the handling of pending revalidation promises to use a provided waitUntil function when available, rather than always assigning directly to options.waitUntil. The changes ensure that background revalidation tasks are properly tracked and awaited in serverless and edge runtime environments.

Changes:

  • Modified test utilities to use retry instead of waitFor for more reliable revalidation testing
  • Added conditional logic to use renderOpts.waitUntil() when available, falling back to options.waitUntil assignment
  • Added debug logging to track when pending revalidation promises complete

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test/e2e/app-dir/app-fetch-deduping/app-fetch-deduping.test.ts Updated test to use retry utility for polling revalidation completion instead of fixed timeout
packages/next/src/server/route-modules/app-route/module.ts Added debug logging for pending revalidation promise completion
packages/next/src/server/base-server.ts Added logic to use provided waitUntil function for pending revalidations in base server
packages/next/src/server/app-render/app-render.tsx Refactored revalidation promise handling to conditionally use renderOpts.waitUntil() or assign to options.waitUntil

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +115 to +118
await retry(async () => {
await next.render('/test')
expect(invocation(next.cliOutput)).toBe(2)
}, 10_000)
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry function is being used to poll for the revalidation to complete, but there's no assertion that the retry succeeded before the timeout. If the invocation count never reaches 2 within 10 seconds, the test should fail with a clear error message. Consider adding error handling or using a retry utility that throws on timeout.

Copilot uses AI. Check for mistakes.
Comment on lines +1301 to +1311
const pendingPromise = Promise.all([
workStore.incrementalCache?.revalidateTag(
workStore.revalidatedTags || []
),
...Object.values(workStore.pendingRevalidates || {}),
...(workStore.pendingRevalidateWrites || []),
])
]).finally(() => {
if (process.env.NEXT_PRIVATE_DEBUG_CACHE) {
console.log('pending revalidates promise finished for:', url)
}
})
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exact code block is duplicated at lines 1468-1478. Consider extracting this logic into a shared helper function to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants