Skip to content

fix(core): revalidate ISR cache for notFound PDP/PLP paths - #3436

Merged
eduardoformiga merged 4 commits into
devfrom
fix/notfound-revalidate-isr
Aug 13, 2026
Merged

eduardoformiga merged 4 commits into
devfrom
fix/notfound-revalidate-isr

Conversation

@eduardoformiga

@eduardoformiga eduardoformiga commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

What's the purpose of this pull request?

PDPs (and PLP/slug pages) that first resolve as notFound were cached forever by Next ISR, so a transient Search/stock miss — often triggered by prefetch — left the path stuck on 404 until a full rebuild. Tracked in SO-650 / SFS-3089

How it works?

When getStaticProps returns notFound: true, it now also sets revalidate (store experimental.revalidate on PDP, otherwise 5 minutes — same window as redirects). Next can regenerate the path after the window instead of freezing the 404.

  • packages/core/src/pages/[slug]/p.tsx
  • packages/core/src/pages/[...slug].tsx

Upgrading to FastStore v4 / Next 16 alone does not fix this; the Pages Router notFound branch had no revalidate before or after that migration.

How to test it?

  • Force a PDP path to generate as 404 (e.g. invalid/unavailable slug with fallback: 'blocking'), confirm response includes a finite revalidation window (not permanent)
  • After the product becomes available in Search again, wait for revalidate (or trigger a stale request) and confirm the path regenerates to 200 without a store rebuild
  • Soft navigation / prefetch no longer leaves a permanently stuck 404 for that path
  • Redirects with enableRedirects still revalidate at 5 minutes

Starters Deploy Preview

Sandbox PR on faststoreqa.store will follow once CodeSandbox CI publishes this commit.

References

Checklist

PR Title and Commit Messages

  • PR title and commit messages follow Conventional Commits (fix)

PR Description

  • Added a label according to the PR goal - bug

Dependencies

  • No lockfile changes

Documentation

  • PR description

Made with Cursor

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Not-found product detail and listing pages now refresh automatically after five minutes by default.
    • Improved handling of not-found and GraphQL errors before displaying product content.
  • New Features
    • Added an optional setting to customize how frequently not-found pages are revalidated, helping newly available pages appear sooner.

Prevent permanent 404 caching when Search/stock gaps cause the first
generation (often via prefetch) to miss a product that later becomes available.
@eduardoformiga
eduardoformiga requested a review from a team as a code owner August 6, 2026 23:03
@eduardoformiga
eduardoformiga requested review from emersonlaurentino and lemagnetic and removed request for a team August 6, 2026 23:03
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cb50a5a9-bad3-4920-832f-3f2e1511e9b6

📥 Commits

Reviewing files that changed from the base of the PR and between 855a3ee and 7c24131.

📒 Files selected for processing (1)
  • packages/core/discovery.config.default.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core/discovery.config.default.js

Walkthrough

Not-found responses in both slug page handlers now use experimental.revalidate404 when configured, with a five-minute fallback. The dynamic slug handler defers product fetching until after not-found and GraphQL error checks.

Changes

Not-found response revalidation

Layer / File(s) Summary
Configure not-found revalidation
packages/core/discovery.config.default.js, packages/core/src/pages/[slug]/p.tsx
The default configuration sets experimental.revalidate404 to 300 seconds. The local StoreConfig type accepts this optional field.
Apply revalidation and defer product fetching
packages/core/src/pages/[...slug].tsx, packages/core/src/pages/[slug]/p.tsx
Not-found responses use experimental.revalidate404 or a five-minute fallback. The dynamic slug handler fetches product data after not-found and GraphQL error checks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • vtex/faststore#3401: Modifies the same PLP and PDP page files for different routing and revalidation concerns.

Suggested reviewers: emersonlaurentino, lemagnetic

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the ISR revalidation fix for not-found PDP and PLP paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/notfound-revalidate-isr

Comment @coderabbitai help to get the list of available commands.

@codesandbox-ci

codesandbox-ci Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

npm i https://pkg.pr.new/vtex/faststore/@faststore/api@7c24131

@faststore/cli

npm i https://pkg.pr.new/vtex/faststore/@faststore/cli@7c24131

@faststore/components

npm i https://pkg.pr.new/vtex/faststore/@faststore/components@7c24131

@faststore/core

npm i https://pkg.pr.new/vtex/faststore/@faststore/core@7c24131

@faststore/diagnostics

npm i https://pkg.pr.new/vtex/faststore/@faststore/diagnostics@7c24131

@faststore/lighthouse

npm i https://pkg.pr.new/vtex/faststore/@faststore/lighthouse@7c24131

@faststore/sdk

npm i https://pkg.pr.new/vtex/faststore/@faststore/sdk@7c24131

@faststore/ui

npm i https://pkg.pr.new/vtex/faststore/@faststore/ui@7c24131

commit: 7c24131

@renatomaurovtex renatomaurovtex 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.

Reviewed the diff plus the surrounding getStaticProps flows in both pages. This is the right minimal fix: the Pages Router notFound branch had no revalidate, so a transient Search/stock miss froze the path on 404 until a rebuild. The change is consistent with the existing 5-minute window already used for the enableRedirects branch, and experimental is already accessed unconditionally in both files, so there's no new undefined risk.

packages/core/src/pages/[slug]/p.tsx

💬 404 window inherits the store's success-page revalidate — a store that sets experimental.revalidate high (e.g. hours) for product pages will now also freeze transient 404s for that long, which works against the goal of this fix (recover quickly from a transient miss). Intentional trade-off, or would you cap it?

-      revalidate:
-        (storeConfig as StoreConfig).experimental.revalidate ?? 60 * 5, // 5 minutes
+      revalidate: Math.min(
+        (storeConfig as StoreConfig).experimental.revalidate ?? 60 * 5,
+        60 * 5
+      ), // never freeze a 404 for longer than 5 minutes

Not blocking — matching the success-page window is also a defensible choice; just confirm it's deliberate.

packages/core/src/pages/[...slug].tsx

💬 PLP/landing hardcodes 60 * 5 while PDP honors experimental.revalidate — consistent with the fact that the PLP success path doesn't use the config either, and matches the PR description. Just confirming the asymmetry is intentional.

Verdict: Approved

Blocking (🔴/🟠):

  • None.

Non-blocking (🟡/💬):

  • 💬 Consider capping the PDP 404 window at 5 minutes when experimental.revalidate is large.
  • 💬 PDP/PLP asymmetry — confirm intentional.

Checks to confirm before merge: build · UI Tests (pending at review time)

Comment thread packages/core/src/pages/[...slug].tsx Resolved
Comment thread packages/core/src/pages/[slug]/p.tsx Resolved
Comment thread packages/core/src/pages/[slug]/p.tsx Resolved
Keep the successful PDP ISR window independent so a long revalidate does not freeze transient 404s.
@eduardoformiga

Copy link
Copy Markdown
Member Author

@renatomaurovtex sobre os pontos do review: em vez de capar o 404 no experimental.revalidate de sucesso, separei em experimental.revalidate404 (default 5 min) e usei a mesma chave na PDP e na PLP. Assim um TTL longo no 200 não congela o miss transitório, e a assimetria PDP/PLP some.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/pages/`[...slug].tsx:
- Around line 218-227: Update the fetchServerManyProducts flow in getStaticProps
to account for its possible undefined result before destructuring. Prefer
propagating the original request error from fetchServerManyProducts, or return
and handle an explicit typed fallback, so failed requests never trigger
“undefined is not iterable” and the original failure remains visible.
- Around line 218-227: Move fetchServerManyProducts back into the successful PLP
Promise.all flow in the page loader, starting it alongside the collection, CMS
content, and global-section requests rather than after they resolve. Preserve
the existing notFound and error checks before awaiting successful results, and
keep the current product query arguments unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 51beabcf-a134-4433-9101-fbf09e140844

📥 Commits

Reviewing files that changed from the base of the PR and between 1d1015e and 855a3ee.

📒 Files selected for processing (3)
  • packages/core/discovery.config.default.js
  • packages/core/src/pages/[...slug].tsx
  • packages/core/src/pages/[slug]/p.tsx

Comment thread packages/core/src/pages/[...slug].tsx Resolved
@sonar-workflows

Copy link
Copy Markdown

@eduardoformiga
eduardoformiga merged commit 039b5cc into dev Aug 13, 2026
11 checks passed
@eduardoformiga
eduardoformiga deleted the fix/notfound-revalidate-isr branch August 13, 2026 13:49
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