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

Dynamic data fetching not working #43879

Open
1 task done
robcaldecott opened this issue Dec 9, 2022 · 5 comments
Open
1 task done

Dynamic data fetching not working #43879

robcaldecott opened this issue Dec 9, 2022 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@robcaldecott
Copy link

Verify canary release

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

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.6.0: Thu Sep 29 20:13:56 PDT 2022; root:xnu-8020.240.7~1/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: 7.11.0
    Relevant packages:
      next: 13.0.7-canary.3
      eslint-config-next: 13.0.6
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Data fetching (gS(S)P, getInitialProps)

Link to the code that reproduces this issue

https://github.com/robcaldecott/nextjs-app-fetch-no-store

To Reproduce

  • Clone the sample repo and run npm run dev.
  • Open http://localhost:3000 and click on the Page with data link.
  • The /data page will load and fetch the current time from a 3rd-party API.
  • Click the Home link to go back to the home page.
  • Click the Page with data link again. The page will not refetch and the previous data will be rendered.

Describe the Bug

I am following the docs trying to use a dynamic fetch to mimic the old getServerSideProps behaviour. I am using { cache: "no-store" } in my fetch but this is only called once when the page first renders whereas I would expect this to be called every time the page loads. Every time the page loads I get the initial data.

I have tried revalidate = 0 and the various segment options to force dynamic but nothing seems to work.

Expected Behavior

I would expect the page to fetch the data every time it loads.

Which browser are you using? (if relevant)

Chrome 108.0.5359.71

How are you deploying your application? (if relevant)

No response

@robcaldecott robcaldecott added the bug Issue was opened via the bug report template. label Dec 9, 2022
@khuezy
Copy link
Contributor

khuezy commented Dec 10, 2022

I have a similar issue when using export const revalidate = 60 for dynamic routes such as: /todo/[id]/page.tsx. The headers are: cache-control: private, no-cache, no-store, max-age=0, must-revalidate.

(on 13.0.6-canary)

@Maksi1994
Copy link

Maksi1994 commented Dec 10, 2022

I have the same issue with /todo/list/page.tsx Option "revalidate=0" doesn't allow to get fresh page.

@zenflow
Copy link
Contributor

zenflow commented Dec 14, 2022

The server-side caching (i.e. revalidate = 0, { cache: "no-store" }) is working like you expect, but the client-side caching (i.e. hard navigation vs soft navigation) is not.
And according to documentation it's not supposed to.

This issue is a duplicate of #42546

@PanuwatChinpratan
Copy link

PanuwatChinpratan commented Jul 8, 2023

I have a similar issue , I have to keep pressing refresh to avoid errors.
log>>>> warn Entire page /projects/[slug] deopted into client-side rendering. https://nextjs.org/docs/messages/deopted-into-client-rendering /projects/[slug]
and Unhandled Runtime Error
Error: Dynamic server usage: no-store fetch https://cheerful-cat-42240.upstash.io/ /projects/[slug]

Source
app\projects[slug]\page.tsx (27:15) @ async PostPage
25 | notFound();
26 | }

27 | const views = (await redis.get(["pageviews", "projects", slug].join(":"))) ?? 0;
| ^
28 | return (
29 |


30 |

My Code
page.zip

Thanks.

@AdorRahman
Copy link

set export const revalidate = 0; in your api/route

example :
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";

export const revalidate = 0;
export async function GET(request: Request) {
try {
const listings = await prisma.listing.findMany();

	return NextResponse.json(listings);
} catch (error) {
	return new Response("Error fetching listings", { status: 500 });
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

6 participants