Skip to content

Scheduled publishing breaks on-demand revalidation: future-dated documents 404 until ISR fallback #1125

Description

@rchlfryn

Note

For now, the times the future publish will get used is not worth the development effort so we are just creating so we do not forget

Summary

When a user sets a future publishedAt date on a document (posts & pages) our on-demand revalidation system can leave that document's path stuck serving a cached 404 even after publishedAt passes and the document should be live. The path only recovers via the 1-hour time-based ISR fallback, which means scheduled publishing is effectively up to 1 hour late.

Originally raised in NWACus/web#1122
(comment)
.

The problem

  1. A user saves a post with publishedAt set in the future.
  2. The save fires our revalidation hook (e.g. revalidatePost.ts). At that moment the post is not considered published (its publishedAt is in the future), so the path is revalidated to a non-published / 404 state and that 404 gets cached.
  3. The clock passes publishedAt. The document is now logically published — but no event fires. Nothing tells Next.js to revalidate the path.
  4. The cached 404 keeps being served. SWR does not help here because the 404 response itself is cached, so subsequent visitors continue to get the stale 404.
  5. The path only self-corrects when the 1-hour time-based revalidation (ISR) safety net kicks in. Net effect: scheduled publishing is always up to ~1 hour behind the intended publish time.

This affects any routable collection that combines a future publishedAt with on-demand revalidation — currently posts, pages, homePages (see docs/revalidation.md → Routable Collections).

Proposed solution

Use Payload's scheduled publish feature, which is built on Payload's Jobs Queue. At the scheduled publish time, the job modifies the document, which fires our existing afterChange revalidation hooks. This correctly revalidates the path right when the content goes live, instead of waiting for the ISR fallback.

This requires standing up the Jobs Queue in this project (not currently configured).

Notes/ TODOs

  • Payload Jobs Queue is configured in the project
  • Scheduled publish via publishedAt triggers on-demand revalidation at publish time (not via the 1-hour ISR fallback)
  • A document with a future publishedAt becomes reachable at its path within a small tolerance of publishedAt, with no stale cached 404
  • Behavior verified for all routable collections (posts, pages, homePages)
  • The existing 1-hour ISR fallback should remain as a safety net.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingready-for-agentFully specified; an AFK agent can pick this up

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions