Skip to content

Enhance cache stale checking logic#1142

Open
conico974 wants to merge 7 commits intomainfrom
conico/interceptor-stale
Open

Enhance cache stale checking logic#1142
conico974 wants to merge 7 commits intomainfrom
conico/interceptor-stale

Conversation

@conico974
Copy link
Copy Markdown
Contributor

Fix cache interceptor not using swr stale logic.
Fix next mode not using stale properly
Update e2e test to reflect that

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 11, 2026

🦋 Changeset detected

Latest commit: 85b01f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/aws@1142

commit: 85b01f8

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 11, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 36.01% 3976 / 11040
🔵 Statements 36.01% 3976 / 11040
🔵 Functions 57.62% 189 / 328
🔵 Branches 79.03% 1063 / 1345
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/open-next/src/core/routing/cacheInterceptor.ts 89.35% 76.84% 100% 89.35% 53, 64-70, 90-91, 121-122, 140-142, 173-176, 232-233, 254-256, 261-262, 275-277, 287-288, 383-384
packages/open-next/src/overrides/tagCache/dynamodb-nextMode.ts 100% 85.39% 100% 100%
packages/open-next/src/overrides/tagCache/fs-dev-nextMode.ts 0% 0% 0% 0% 1-98
packages/open-next/src/overrides/tagCache/fs-dev.ts 0% 0% 0% 0% 1-106
Generated in workflow #1777 for commit 85b01f8 by the Vitest Coverage Report Action

if (finalRevalidate !== CACHE_ONE_YEAR || isStaleFromTagCache) {
const sMaxAge = isStaleFromTagCache
? 1
: Math.max(finalRevalidate - age, 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: redundant Math.max(finalRevalidate - age, 1)

Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

LGTM with a few nits

"@opennextjs/aws": patch
---

Fix cache interceptor isStale handling for Next 16+
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR description lists 2 fixes.
They should probably both be listed here.

}
if (finalRevalidate !== CACHE_ONE_YEAR) {
const sMaxAge = Math.max(finalRevalidate - age, 1);
const isTimeStale =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nits:

  • should the name be isStaleFromTime for consistency ?
  • add a comment why CACHE_ONE_YEAR is special cased

Math.max(finalRevalidate - age, 1) === 1;
const isStale = isTimeStale || isStaleFromTagCache;

if (finalRevalidate !== CACHE_ONE_YEAR || isStaleFromTagCache) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit

finalRevalidate !== CACHE_ONE_YEAR is computed twice too.

Extract to a const with a comment?

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.

3 participants