Skip to content
Discussion options

You must be logged in to vote

You can achieve this by using Incremental Static Regeneration together with on-demand revalidation in Next.js. Essentially, you serve a pre-rendered (cached) version instantly, but can update it the moment your data changes. In the App Router, you can disable automatic time-based invalidation by setting export const revalidate = 0;. Then, whenever your WebSocket detects a database update trigger a revalidation request to your API route. This way the user immediately receives the last cached content while your client-side WebSocket keeps it live and reactive after hydration. Once the data changes, the cache for that route is instantly refreshed for future requests.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@R5dan
Comment options

@haroonmaqbool
Comment options

@R5dan
Comment options

@haroonmaqbool
Comment options

Answer selected by R5dan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants