Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix: langing page footer cached to display incorrect version, two solutions #469

Closed
wants to merge 2 commits into from

Conversation

KemingHe
Copy link
Collaborator

@KemingHe KemingHe commented Dec 20, 2024

Problem

Landing page and other static assets are cached for 1 year by NextJS 15 default setting, read more here: https://nextjs.org/docs/app/api-reference/config/next-config-js/headers#cache-control

Current production landing page (static) footer displays the outdated version of v12.7.0,

Screenshot 2024-12-20 at 12 02 43 PM

while the dynamic repo preview config page doesn't have this issue, and display the correct version of v2.18.1.

Screenshot 2024-12-20 at 12 02 31 PM

Solution Candidates

To resolve #462

1. Request Header-based

Allow static pre-rendering of landing page, but force revalidate in request headers for all routes (can change to just landing page as well), set in next.config.js:

https://github.com/KemingHe/contrib-socialify/blob/c40619c964394501781de6d8458c527cf1fe8654/next.config.js#L26-L54

2. Build-based

Put export const dynamic = 'force-dynamic in app/layout.tsx to force dynamic for all routes, disabling static pre-rendering (can change to just setting it for landing page as well).


I'm open to other proposals and heads-ups, still learning here. ☀️ Edit: additional context.

Copy link

changeset-bot bot commented Dec 20, 2024

🦋 Changeset detected

Latest commit: c40619c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
socialify 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

Copy link

netlify bot commented Dec 20, 2024

Deploy Preview for github-socialify ready!

Name Link
🔨 Latest commit c40619c
🔍 Latest deploy log https://app.netlify.com/sites/github-socialify/deploys/6765a4b066ad160007b2b2fb
😎 Deploy Preview https://deploy-preview-469--github-socialify.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@KemingHe KemingHe marked this pull request as draft December 20, 2024 17:10
@KemingHe
Copy link
Collaborator Author

KemingHe commented Dec 20, 2024

Another unexpected find is that the server-side, pre-rendered not-found.tsx page actually has the correct footer. @wei This... doesn't make sense, converting to draft for further discussion. Edit: typo

@wei
Copy link
Owner

wei commented Dec 20, 2024

Thanks for looking into it! Per docs the 1 year cache should only apply to static and tagged immutable assets, very bizarre it's applied to pages too. I'm totally fine with pre-rendering but the pre-rendered version should not be cached for 1 year.

I'll also do some more digging when I get time.

@KemingHe
Copy link
Collaborator Author

This is the build output detailing the type of each of our routes (taken from latest build GitHub Actions run: https://github.com/wei/socialify/actions/runs/12435500119/job/34721445420?pr=469) for more context:

Route (app)                              Size     First Load JS
┌ ○ /                                    3.33 kB         114 kB
├ ○ /_not-found                          155 B           106 kB
├ ƒ /[_owner]/[_name]                    52.3 kB         163 kB
├ ƒ /api/font                            155 B           106 kB
├ ƒ /api/graphql                         155 B           106 kB
├ ƒ /api/image                           155 B           106 kB
├ ƒ /api/png                             155 B           106 kB
├ ƒ /api/stats                           155 B           106 kB
├ ƒ /api/stats.svg                       155 B           106 kB
├ ƒ /api/svg                             155 B           106 kB
├ ○ /apple-icon.png                      0 B                0 B
├ ○ /icon.png                            0 B                0 B
├ ○ /icon.svg                            0 B                0 B
└ ○ /manifest.json                       0 B                0 B
+ First Load JS shared by all            106 kB
  ├ chunks/561-9f2716095132ab78.js       50.9 kB
  ├ chunks/e60cd844-3119e9860051c9f6.js  52.9 kB
  └ other shared chunks (total)          1.91 kB


○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand

@wei
Copy link
Owner

wei commented Dec 20, 2024

I noticed making pages use edge runtime will prevent ISR which was setting the cache headers. We'd want to use edge runtime anyways so I will pop that in #470.

@wei wei closed this in #470 Dec 20, 2024
@KemingHe KemingHe deleted the fix-footercacheissue-keminghe branch December 21, 2024 14:32
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.

Unexpected Caching after Next.js 15 Upgrade
2 participants