Skip to content

fix(cacheInterceptor): handle index route cache key#1189

Merged
conico974 merged 3 commits into
opennextjs:mainfrom
gaauwe:fix/cache-interceptor-index-route
Jun 25, 2026
Merged

fix(cacheInterceptor): handle index route cache key#1189
conico974 merged 3 commits into
opennextjs:mainfrom
gaauwe:fix/cache-interceptor-index-route

Conversation

@gaauwe

@gaauwe gaauwe commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

We noticed that our index page was not being served by the cache interceptor even though enableCacheInterception was enabled.

This is similar to #860, but the existing fix still uses ?? fallbacks. After trailing slash normalization, / becomes an empty string, so localizedPath ?? "/" still evaluates to "".

This normalizes the route path back to / for ISR detection, while keeping /index as the cache lookup key to match the generated cache asset.

Verified against a Cloudflare/OpenNext build:

  • prerender manifest route key: /
  • generated cache asset: index.cache
  • populated cache key: /index

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8cc70bc

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

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 8cc70bc

@conico974 conico974 left a comment

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.

Could you add some unit test ?


// Then we decode the path params
localizedPath = decodePathParams(localizedPath);
localizedPath = decodePathParams(localizedPath) || "/";

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.

localizedPath is used in the rest of the files in a couple of places (i.e. hasBeenRevalidated, isStale).
Did you check if it has the right value there ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! It seems that I indeed missed the usage in hasBeenRevalidated and isStale, which should use the cacheKey.

I've added some tests to validate the behavior:

  • /albums still uses /albums for the cache lookup and 'original-mode' cache checks, so existing non-index behavior is unchanged
  • The new index cache key test fails without the route normalization, and now passes.
  • The same index cache key test failed after my initial fix, because hasBeenRevalidated and isStale still received /
    • It now verifies that 'original-mode' tag cache checks use /index
  • The new stale index route path test verifies that background revalidation still uses the public route /, not the cache key /index

As you can imagine this code is all new to me, so let me know if there is anything I can improve (:

@conico974 conico974 left a comment

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.

LGTM, Thanks for the PR

@conico974 conico974 merged commit 8a2ebf2 into opennextjs:main Jun 25, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 25, 2026
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