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

Routes using data fetching methods return 304 on non-conditional requests #56018

Closed
1 task done
kevineinarsson opened this issue Sep 26, 2023 · 80 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@kevineinarsson
Copy link

kevineinarsson commented Sep 26, 2023

Link to the code that reproduces this issue

https://github.com/kevineinarsson/next-revalidate-issue

To Reproduce

  1. Start the application in production mode (build & start)

  2. Curl one of the routes:

curl -I http://localhost:3000 (static)
curl -I http://localhost:3000/1 (dynamic)

These should return 200:s, no matter how many times you curl. Note the x-nextjs-cache header which indicates whether a revalidation of the content is performed (due to fetch options including next: { revalidate: 5 })

curl -I http://localhost:3000 -H 'If-None-Match: "<etag from previous request>"'
curl -I http://localhost:3000/1 -H 'If-None-Match: "<etag from previous request>"'

This should return a 304, since we're matching against an ETag and the content matches.

However, if a revalidation occurs from a request that includes a If-None-Match header, the .meta will now contain status: 304, causing subsequent requests without an ETag to return 304 not modified, which should not happen.

Current vs. Expected behavior

Cache updates should not store conditional headers such as 304. The result of the operations above should be a 200 in the metadata file.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
Binaries:
  Node: 20.6.1
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: 8.7.5
Relevant Packages:
  next: 13.5.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

Issue does not appear on 13.4.17.

In dynamic routes, removing generateStaticParams() makes the problem disappear, but doing so leads to a response without an ETag.
Using export const dynamic = 'force-dynamic'; works for static pages, but of course makes them dynamic.

NEXT-1699

@kevineinarsson kevineinarsson added the bug Issue was opened via the bug report template. label Sep 26, 2023
@sleeporsmile
Copy link

sleeporsmile commented Sep 26, 2023

@apricote
Copy link

apricote commented Sep 28, 2023

We encounter the same symptoms, reproducible on 14.0.1-canary.0

Unlike the OP, we do not use dynamic routes & generateStaticParams. Instead we just use fetch on a regular app route:

const res = await fetch(endpoint, {
  headers: { Authorization: `Bearer XYZ` },
  next: {
    revalidate: 60,
  },
});

@mircostraessle
Copy link

We ran into the same issue (13.5.1 with app folder on production and self-hosted with standalone build) were some of our static routes with export const revalidate = XX; started returning http 304 codes and users would only see a white, blank page or if directly called via url bar nothing at all.

As a workaround we resorted to using export const dynamic = 'force-dynamic'; on these routes instead of revalidating the static routes. That seems to resolve this bug for the moment but of course isn't what we would like to do.

@kevineinarsson kevineinarsson changed the title Dynamic routes using generateStaticParams are cached with status: 304 after revalidation Routes using data fetching methods return 304 on non-conditional requests Oct 3, 2023
@kevineinarsson
Copy link
Author

Updated reproduction repo with a static page.

@FredTreg
Copy link

FredTreg commented Oct 3, 2023

Same issue for me, can't upgrade from 13.4.12

@SimonyanGrno
Copy link

We're facing a similar issue. We upgraded to version 13.5.3 to address memory leaks, but now we're encountering the 304 code and a white screen after revalidation.

@daynejones
Copy link

daynejones commented Oct 5, 2023

Same problem in production on 13.4.19 and 13.5.4.

Getting 304, Not Modified and empty response bodies.

Downgraded all the way to 13.4.12 until this is fixed.

@Aziaev
Copy link

Aziaev commented Oct 6, 2023

I face same issue after upgrading to 13.5.3

@hk86
Copy link

hk86 commented Oct 7, 2023

same issue with 13.5.4

@sleeporsmile

This comment has been minimized.

@syed-ahmad
Copy link

We have a catch-all dynamic route [...path] with generateStaticParams and generateMetaData.

export const dynamicParams = true;

export const revalidate = 10;

export async function generateMetadata(
  { params: { path } }: Props,
  parent: ResolvingMetadata,
): Promise<Metadata> {
  const { page = {} as Page } = await getPageContent({ path });

  return {
    title: page.title
  };
}


export const generateStaticParams = async () => {
  const pagePaths = await getPaths();

  const paths = pagePaths.map((pagePath) => ({
    path: pagePath.split('/'),
  }));

  return paths;
};

export default async function Page({
  params: { path },
}: {
  params: { path: PagePaths };
}) {
  const { page  } = await getData({ path });

  return <>Page content goes here</>;
}

Then we do a next build (standalone) and deploy that to Azure ASE on a linux docker container and fire up the server using node server.js.

So, for all the statically generated pages we get a 200 OK but it seems the ones generated on the fly seems to return 304 Not Modified either straightaway or after a while.

But, once you get a 304 Not Modified header on the client (browser), you start to see a blank page.

@DanStuartDept
Copy link

@syed-ahmad Our code looks very similar and we encountered the same issue. when we built our docker image and ran it locally we could even reproduce the error.

We just had to leave it running a bit (presumably when next.js cache revalidates) and eventually we got back blank pages with 304 Not Modified.

For now we have removed generateStaticParams from our dynamic route.

@zrtsky
Copy link

zrtsky commented Oct 11, 2023

same issue when upgrade to 13.5.X ...

@velopert
Copy link

We faced this issue in 13.5.4.

304 with blank page.

image

We are running Next.js server on docker container instead of getting hosted on Vercel.

We disabled caching for now.

@zrtsky
Copy link

zrtsky commented Oct 12, 2023

We faced this issue in 13.5.4.

304 with blank page.

image

We are running Next.js server on docker container instead of getting hosted on Vercel.

We disabled caching for now.

Same

@digitaldonmedia
Copy link

Same issue here. Self-hosted website with app router. I'm stuck on version 13.4.19.
I'm not using generateStaticParams, just a simple served component fetching dynamic data with revalidate

@hyn-lei
Copy link

hyn-lei commented Oct 14, 2023

npm run build can help in my experience, rather than using yarn run build.

@velopert
Copy link

npm run build can help in my experience, rather than using yarn run build.

I am using pnpm here !

@l-you
Copy link

l-you commented Oct 18, 2023

Self-hosted website with app router. I'm stuck on version 13.4.19. I'm not using generateStaticParams, just a simple served component fetching dynamic data with revalidate

Same here. We are trying a new NextJs version each time it release and it's broken each time. Still using 13.4.19.

@zrtsky
Copy link

zrtsky commented Oct 18, 2023

Self-hosted website with app router. I'm stuck on version 13.4.19. I'm not using generateStaticParams, just a simple served component fetching dynamic data with revalidate

Same here. We are trying a new NextJs version each time it release and it's broken each time. Still using 13.4.19.

We use 13.4.5, and it's also works fine

123

@haakondrang
Copy link

We have the same problem for all 13.5.x and are stuck on 13.4.19. It only happens in production, and we are not able to reproduce it locally.

@thijsadrmat
Copy link

We encountered this issue as well on a self hosted NextJs project. Switching back to 13.4.19 was indeed the solution for now.

@sleeporsmile
Copy link

It's still present in 13.5.6 standalone production mode. reverted to 13.4.19

@pma9
Copy link

pma9 commented Oct 20, 2023

Hi @balazsorban44 I saw you closed a related issue and I was just wondering if Next has their eye on this one I didnt see any members in the comments so hoping its on the radar

@sinaprgm1376
Copy link

I have the same problem, and my project is facing issues and has come to a complete halt.
I hope the members resolve the issue in Next.

@smuk3c
Copy link

smuk3c commented Nov 17, 2023

Does not work for me :/ Anyone else?

@paataD
Copy link

paataD commented Nov 19, 2023

Same situation. In standalone prod mode sometimes heppens 304, nextjs 13.5.6. Now I want rto try with 14.0.2

@paataD
Copy link

paataD commented Nov 20, 2023

After 12 hours on prod same error with 304 response on version 14.0.3 =(

@marco910
Copy link

I'm testing on v14.0.2 and currently it's running without issues in production. I will keep an eye on it. Maybe the issue comes up in the next days again...

@MartinaMilisic
Copy link

After 12 hours on prod same error with 304 response on version 14.0.3 =(

I had the same problem initially, with 14.0.2 (running standalone on azure web app - node 20 lts). I had to remove the old node_modules folder in the azure resource for it to work. I haven't figured out how to replace old files/folders in the azure resource automatically instead of just patching existing. When removing them manually and deploying again it seems to be working. Has been up since Friday afternoon. Crossing my fingers that it will keep on working...

@awinogrodzki
Copy link

@paataD does it happen even after you remove .next/cache directory?

@paataD
Copy link

paataD commented Nov 22, 2023

@paataD does it happen even after you remove .next/cache directory?

Sorry, it's work perfect on 14.0.*, thank you!

@justrealmilk
Copy link

Related #58646

@dmitriigirskii
Copy link

Yes, upgrading to the latest versions worked.

@marco910
Copy link

Seems also to work on my website running on Next.js 14.0.2

@vanyapr
Copy link

vanyapr commented Nov 28, 2023

Upgrading to latest version doesnt works for me, on production it still sends empty responce with 304 status.

@timstarbuck-boystown
Copy link

timstarbuck-boystown commented Dec 4, 2023

Ran into this issue on a production site running 13.5.4. Can anyone verify is the issue is fixed on a version > 13.5.4? Or 14? There are notes of the issue still being present there. #57737

@SaXaPhonist
Copy link

the issue is also in v14.0.1 only in production mode

@Francismori7
Copy link

We are also suffering from this. The site responds fine for some users, but some are unable to open it at all.

@smuk3c
Copy link

smuk3c commented Dec 11, 2023

nextjs 14.0.4 still have this issue for me :(

@adisaktijrs
Copy link

Yes, upgrading to the latest versions worked.

hi @dmitriigirskii what version did you use? And is it really fixed this issue? Thanks

@xecrets
Copy link

xecrets commented Dec 14, 2023

Yes, upgrading to the latest versions worked.

hi @dmitriigirskii what version did you use? And is it really fixed this issue? Thanks

@smuk3c says it's still in 14.0.4 and that is as far as I can tell, the most recent version. So, it appears that it's not certain that it's fixed.

@adisaktijrs
Copy link

Yes, upgrading to the latest versions worked.

hi @dmitriigirskii what version did you use? And is it really fixed this issue? Thanks

@smuk3c says it's still in 14.0.4 and that is as far as I can tell, the most recent version. So, it appears that it's not certain that it's fixed.

Upgraded my project to 14.0.4 last week, and both issue of generateStaticParams and fetch revalidate seems fixed

@KenChang-TVBS
Copy link

have problem in 13.5.5.
only on production mode, encounter page get 304 code

@samcx
Copy link
Member

samcx commented Jan 2, 2024

@kevineinarsson Can you confirm if you are still experiencing 304s with the latest Next.js 14.0.4? I was not able to confirm this with the latest Next.js (v14.0.4).

@ciruz
Copy link
Contributor

ciruz commented Jan 3, 2024

We have the same issue with dynamic routes; right now we are on v13.5.6, but our dev environment is on v14.0.3. We are going to update the dev to v14.0.4, sadly it will take some time to go into production, but hopefully the error will be resolved. Will report back.

@V-iktor
Copy link

V-iktor commented Jan 5, 2024

Happened to me on 14.0.1 but seems to be fixed by upgrading to 14.0.4

Will update if it occurs again 👀

@Patrikur
Copy link

Same here on 14.0.1, updated to 14.0.4 and it worked again!

@charlottedamm
Copy link

We're having this issue still on 14.1.0

@samcx
Copy link
Member

samcx commented Jan 30, 2024

Since we are no longer getting this issue on the latest version, I will proceed with closing this issue!

If this issue arises again, please feel free to submit a new bug report so we can take a look!

@samcx samcx closed this as completed Jan 30, 2024
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.