next.js icon indicating copy to clipboard operation
next.js copied to clipboard

[appDir][Dynamic Rendering] Dynamic Data Fetching doesn't seem to be fully working (various bugs in Data Fetching & Route Segment Config Options)

Open gfortaine opened this issue 3 years ago • 5 comments

Verify canary release

  • [X] 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: 16.18.1
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: N/A
Relevant packages:
  next: 13.0.3
  eslint-config-next: N/A
  react: 18.3.0-next-fecc288b7-20221025
  react-dom: 18.3.0-next-fecc288b7-20221025

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

It seems that we have had a hard time setting up Dynamic Rendering. Indeed, it looks like that many of the various options are still KO at the time of writing :

At the end of the day, only revalidate with a value of 0 did the trick

Expected Behavior

Options to enable Dynamic Rendering described in the documentation should work :

https://beta.nextjs.org/docs/rendering/static-and-dynamic-rendering#dynamic-rendering

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

https://github.com/vercel/next-react-server-components

To Reproduce

Clone the repo and use the various options (except revalidate with a value of 0 that is working) in the ItemPage Server Component (/app/item/page.js). Then, you will see the bug when trying to go on the /item page with the following error message :

An item with an ID must be provided as a query parameter.

gfortaine avatar Nov 13 '22 15:11 gfortaine

It seems that the current tests are KO (test/e2e/app-dir/app-static-test.ts, https://github.com/vercel/next.js/pull/41505). Indeed, it looks like that we shouldn't use Date.now() to ensure that we have the expected behaviour. Another possibility could be to check if searchParams is correctly handled by the Server Component (like what is done in the repository aforementioned).

gfortaine avatar Nov 13 '22 15:11 gfortaine

Same for me! I use 13.0.3 It seems that everything is statically generated at build time.

dumbravaandrei22 avatar Nov 13 '22 23:11 dumbravaandrei22

@gfortaine we will look into this. For future reference, please refrain from mass tagging core maintainers. :pray: :green_heart:

balazsorban44 avatar Nov 14 '22 11:11 balazsorban44

@balazsorban44 As a side note, it seems that the bug appears only in production mode (run build) not in development

gfortaine avatar Nov 15 '22 07:11 gfortaine

Encountering the same thing, the dynamic option is completely ignored it seems. image

I've tested as well that revalidate: 0 in fetch calls is one option to force SSR as @gfortaine stated. An alternative I found was to use call import { previewData } from 'next/headers' to force SSR again.

image

A quick note for those using preview mode though, you can't make it work with ISR on the same page component. Since this behavior I noted above will force it to SSR no matter what. I had to use previewData on a separate route for that feature I needed to implement.

jmcruzmanalo avatar Nov 16 '22 01:11 jmcruzmanalo

Same for me.

For me, export const dynamic='force-dynamic' does not work totally now. Only export const revalidate = 0 works.

I also wonder whether export const dynamic='force-dynamic' is equal to export const revalidate = 0.

At least according to the document, I think expected behavior of export const dynamic='force-dynamic' is equal to export const revalidate = 0, but not sure it's rational. https://beta.nextjs.org/docs/api-reference/segment-config#dynamic image

sumiren avatar Nov 21 '22 02:11 sumiren

@gfortaine fyi

Upgraded to [email protected] and the issue seem to have been fixed. https://github.com/vercel/next.js/issues/43191#issuecomment-1363403154

zenflow avatar Dec 22 '22 23:12 zenflow

Hello! I can still reproduce this in 13.1.1 and 13.1.2-canary.4 dev and build mode. @gfortaine Can we reopen this? If we cannot, I will file a new issue.

Did you manage to solve this using 13.1.1?

dumbravaandrei22 avatar Jan 16 '23 23:01 dumbravaandrei22

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

github-actions[bot] avatar Feb 16 '23 00:02 github-actions[bot]