CDN purge and version mismatch when self-hosting Next.js #70518
Unanswered
haapti
asked this question in
App Router
Replies: 1 comment
-
Have you found any solutions on how to deal with this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Anyone faced issues with version mismatch when caching Next.js app on CDN?
What we learned so far?
We cant have multiple different versions of HTML documents and RSC payloads on CDN of same Next.js app. Version needs to be same between all HTML documents and RSC payloads, and between origin Next.js server. Next.js version will change on every new build.
Caused issues
Hard navigation loop: Next.js will automatically reload the application to retrieve new assets when detected. For example, if there is a mismatch in the deploymentId, transitions between pages will perform a hard navigation versus using soft navigation. If RSC payloads are in different version to HTML documents hard navigation is performed on each navigation what is not desired for SPA web app.
Version mismatch client vs. server: If different versions of Next.js application run on client and server, it causes application errors and other unexpected behavior. For example, imagine your newest deployment modifies the data structure by adding a required field to a user's profile. Older clients wouldn't expect this new field, leading to errors when they submit it via POST to backend Next.js server.
Version
Next.js 14.x with app directory using static and SSG pages.
Terminology
HTML document
Initial HTML payload when user open any page/route first time
RSC Payload
Client either prefetches or fetches the RSC Payload on navigation. For example, when navigating to
/page-2
you see RSC fetch/page-2?_rsc=xxx
happening on background.On the client:
References
How to solve the issue?
We very likely need to purge the cache in way or another after every build. This does not feel desired option for hightraffic site.
Options in the air:
Cache-tag: document
Beta Was this translation helpful? Give feedback.
All reactions