Data gets fetched in preview, but not production deployments

Hey, so we are trying to migrate our project from pages router to app router but we’ve been dealing with a nasty and hard-to-debug issue. We are on Next 14.2.3. If it helps, we have clientRouterFilter: false

In preview:

ezgif.com-video-to-gif-converter

As you can see, when you load the page, the swr hook loads the uploaded files, as expected. Link is here: https://stackweb-7212akqiq-stack-ai.vercel.app/form/56955d69-a10f-49d9-85cc-46a6d1bd5f5a/5e662b32-89d5-432a-9251-890c3a14d6bd/67c0ca6d4df3c68b2987064f

In production:

prod-ezgif.com-video-to-gif-converter

However, in production, the files never fetch. They only get fetched when you click the page. Note, the code running here is exactly the same as the preview deployment, and this has been happening for a while only in prod. Link is here: Test Form

Network tab:

image-fetch-ezgif.com-video-to-gif-converter

Here’s the really strange thing. This strange behavior doesn’t seem to be limited to SWR per se. In prod, even images are being refetched on click!

We know that putting use client at the top of page.tsx solves the issue, but we do not want to do this. We also know that importing a component as dynamic solves this, but we also do not want to do this. We want to use the SSR features of app router, and we’re really bummed that we cannot take advantage of them.

If anyone has any potential insights here, that would be amazing!

1 Like

Same! This is so weird, seems like a misconfiguration? Cannot be such an obvious bug

1 Like

https://www.reddit.com/r/nextjs/s/VECjSNXx3c

Apparently someone else had this issue with the production deployments: seems exact the same as ours. No fetching in app router in prod until you click the page. But we do not want to “solve” it the way they did (import the component as dynamic)

We found the issue! google analytics script tag was breaking hydration, and we only had it enabled in production. For those who may come to this thread, check your layout and make sure to block these scripts from rendering in the client.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.