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

bug: Cannot generate static page #2006

Open
DawnMD opened this issue Oct 28, 2024 · 1 comment
Open

bug: Cannot generate static page #2006

DawnMD opened this issue Oct 28, 2024 · 1 comment
Labels
❓ question Further information is requested works as expected

Comments

@DawnMD
Copy link

DawnMD commented Oct 28, 2024

Provide environment information

  System:
    OS: macOS 15.0.1
    CPU: (8) arm64 Apple M2
    Memory: 89.05 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.9.0 - ~/Library/Caches/fnm_multishells/23543_1730102638399/bin/node
    npm: 10.2.5 - ~/Library/Caches/fnm_multishells/23543_1730102638399/bin/npm
    pnpm: 9.4.0 - ~/Library/Caches/fnm_multishells/23543_1730102638399/bin/pnpm

Describe the bug

Pages are not generated statically when prefetching in a page or directly in a layout. If we remove all prefetch (be it await or void) then pages are generated statically.

Its mostly an issue when fetching some data from a CMS, as prefetch all or each the data from CMS will be a good way to render page statically

Tried to use next 15's static page symbol after upgrading, there also no static page symbol is showing when prefetching at the page/layout

Reproduction repo

https://github.com/t3-oss/create-t3-app

To reproduce

  1. Scaffold the app with
    • App router
    • tRPC
    • Tailwind
  2. Update the build script with --debug
  3. You'll get Static generation failed due to dynamic usage on /, reason: headers

Additional information

With prefetch at page level
image

Without prefetch
image

@juliusmarminge
Copy link
Member

Isn't this correct? headers() rejects so Next knows to make the page dynamic? I think this is just an internal error that they catch, if there was an actual issue the error would show without --debug flag?

Pages are not generated statically when prefetching in a page or directly in a layout.

No, you'd need to export const dynamic = 'force-static' to force dynamic when doing dynamic stuff. If you do so the trpc procedures runs during build and the page is outputted as static:
CleanShot 2024-11-04 at 09 39 46

So I'm not sure what the issue is

@juliusmarminge juliusmarminge added ❓ question Further information is requested works as expected and removed 🐞❔ unconfirmed bug labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Further information is requested works as expected
Projects
None yet
Development

No branches or pull requests

2 participants