[Bug]: Issue with data revalidation after new build
krystianolech opened this issue · 3 comments
Summary
Hello,
I have spotted some issue with cache invalidation when using nextjs project.
Whenever app is deployed cache value back to value form previous deployment rather then last cache update.
To clarify that I created sample application that fetch current time using external API.
Implementation looks like this:
``typescript
const revalidatedData: {
dateTime: string;
date: string;
time: string;
} = await (
await fetch(
https://timeapi.io/api/Time/current/zone?timeZone=Europe/Amsterdam
,
{
next: { revalidate: 60 },
}
)
).json();
``
Then I observer values shown after initial deployment:
- First call
17:54:42 => 2024-03-16T17:54:05.4640449
Return fresh value as expected - Calling after >1 min.
Return cached value but trigger invalidation in the background as expected
17:56:00 => 2024-03-16T17:54:05.4640449 - 20 sec later Return more-up-to-date value that was cached as action of previous call (which invalidated cache)
17:56:20 => 2024-03-16T17:56:02.3781541 - After >1 min previous value is returned and cache is invalidated
17:58:20 => 2024-03-16T17:56:02.3781541 - 20 sec later Return more-up-to-date value that was cached as action of previous call (which invalidated cache)
17:58:36 => 2024-03-16T17:58:20.1347378
So far so good.
Now I trigger new build, in this case by committing minor change
Build completes at 18:03
Accessing page 20 seconds later shows
2024-03-16T17:54:05.4640449
A link to a reproduction repository
https://github.com/krystianolech/netlify-next-issue
Expected Result
After deployment data should be revalidated so it would shown latest state or at least last cached state
Actual Result
Data that is shown is older then then last seen data (2024-03-16T17:58:20.1347378) as its date back to previous build.
It means that deploy is actually leading to showing outdated data
Steps to reproduce
Please use reporsitory provided in example and described steps.
It is enough to trigger deployment in order to produce this issue.
Next Runtime version
4.41.3
Is your issue related to the app
directory?
- Yes, I am using the
app
directory
More information about your build
- I am building using the CLI
- I am building using file-based configuration (
netlify.toml
)
What OS are you using?
None
Your netlify.toml file
6:02:40 PM: Netlify Build
6:02:40 PM: ────────────────────────────────────────────────────────────────
6:02:40 PM:
6:02:40 PM: ❯ Version
6:02:40 PM: @netlify/build 29.36.3
6:02:40 PM:
6:02:40 PM: ❯ Flags
6:02:40 PM: baseRelDir: true
6:02:40 PM: buildId: 65f5d08c0382d700085ecb92
6:02:40 PM: deployId: 65f5d08c0382d700085ecb94
6:02:40 PM:
6:02:40 PM: ❯ Current directory
6:02:40 PM: /opt/build/repo
6:02:40 PM:
6:02:40 PM: ❯ Config file
6:02:40 PM: No config file was defined: using default values.
6:02:40 PM:
6:02:40 PM: ❯ Context
6:02:40 PM: production
6:02:41 PM:
6:02:41 PM: ❯ Using Next.js Runtime - v4.41.3
6:02:42 PM:
6:02:42 PM: @netlify/plugin-nextjs (onPreBuild event)
6:02:42 PM: ────────────────────────────────────────────────────────────────
6:02:42 PM:
6:02:42 PM: Next.js cache restored.
6:02:42 PM:
6:02:42 PM: (@netlify/plugin-nextjs onPreBuild completed in 101ms)
6:02:42 PM:
6:02:42 PM: Build command from Netlify app
6:02:42 PM: ────────────────────────────────────────────────────────────────
6:02:42 PM:
6:02:42 PM: $ npm run build
6:02:42 PM: > test-netlify@0.1.0 build
6:02:42 PM: > next build
6:02:43 PM: ▲ Next.js 14.1.3
6:02:43 PM: Creating an optimized production build ...
6:02:46 PM: ✓ Compiled successfully
6:02:46 PM: Linting and checking validity of types ...
6:02:48 PM: Collecting page data ...
6:02:49 PM: Generating static pages (0/5) ...
6:02:49 PM: Generating static pages (1/5)
6:02:49 PM: Generating static pages (2/5)
6:02:49 PM: Generating static pages (3/5)
6:02:49 PM: ✓ Generating static pages (5/5)
6:02:49 PM: Finalizing page optimization ...
6:02:49 PM: Collecting build traces ...
6:02:54 PM: Route (app) Size First Load JS
6:02:54 PM: ┌ ○ / 137 B 84.4 kB
6:02:54 PM: └ ○ /_not-found 882 B 85.1 kB
6:02:54 PM: + First Load JS shared by all 84.3 kB
6:02:54 PM: ├ chunks/69-c292296505fe2927.js 29 kB
6:02:54 PM: ├ chunks/fd9d1056-c7082c319cc53ced.js 53.4 kB
6:02:54 PM: └ other shared chunks (total) 1.87 kB
6:02:54 PM: ○ (Static) prerendered as static content
6:02:54 PM:
6:02:54 PM: (build.command completed in 12s)
6:02:54 PM:
6:02:54 PM: @netlify/plugin-nextjs (onBuild event)
6:02:54 PM: ────────────────────────────────────────────────────────────────
6:02:54 PM:
6:02:54 PM: Moving static page files to serve from CDN...
6:02:54 PM: Moved 4 files to CDN
6:02:54 PM: You are not using Netlify Edge Functions for image format detection. Set env var "NEXT_FORCE_EDGE_IMAGES=true" to enable.
6:02:54 PM:
6:02:54 PM: (@netlify/plugin-nextjs onBuild completed in 254ms)
6:02:54 PM:
6:02:54 PM: Functions bundling
6:02:54 PM: ────────────────────────────────────────────────────────────────
6:02:54 PM:
6:02:54 PM: Packaging Functions from .netlify/functions-internal directory:
6:02:54 PM: - ___netlify-handler/___netlify-handler.js
6:02:54 PM: - ___netlify-odb-handler/___netlify-odb-handler.js
6:02:54 PM: - _ipx/_ipx.js
6:02:54 PM:
6:03:10 PM:
6:03:10 PM: (Functions bundling completed in 16s)
6:03:10 PM:
6:03:10 PM: Edge Functions bundling
6:03:10 PM: ────────────────────────────────────────────────────────────────
6:03:10 PM:
6:03:10 PM: Packaging Edge Functions from .netlify/edge-functions directory:
6:03:10 PM: - rsc-data
6:03:11 PM:
6:03:11 PM: (Edge Functions bundling completed in 567ms)
6:03:11 PM:
6:03:11 PM: @netlify/plugin-nextjs (onPostBuild event)
6:03:11 PM: ────────────────────────────────────────────────────────────────
6:03:11 PM:
6:03:11 PM: Next.js cache saved.
6:03:11 PM:
6:03:11 PM: (@netlify/plugin-nextjs onPostBuild completed in 87ms)
6:03:11 PM:
6:03:18 PM: (Netlify Build completed in 37.7s)
6:03:19 PM: Section completed: building
6:03:22 PM: Finished processing build request in 1m1.461s
Your public/_redirects file
`_redirects`
# Paste content of your `_redirects` file here
Your next.config.js
file
`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.
Builds logs (or link to your logs)
Build logs
# Paste logs here
Function logs
Function logs
# Paste logs here
.next JSON files
generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.
Hi @krystianolech ,
Could you try opting-in to the new runtime and see if the issue persists.
We are using v5, and whenever we make a new deployment, we have to force a full refresh or incognito on the browser to get latest version.
Next 14.1 with plugin v5.
ok, I tested in v5.0.0-rc.6 and issue is now gone, thank you :)