cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages
https://www.npmjs.com/package/@cloudflare/next-on-pages
MIT License
1.3k stars 126 forks source link

[πŸ› Bug]: __PRERENDER_MANIFEST duplication #869

Open Y90SMH opened 2 months ago

Y90SMH commented 2 months ago

next-on-pages environment related information

System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030 CPU: (11) arm64 Apple M3 Pro Memory: 18 GB Shell: /bin/zsh Package Manager Used: npm (10.8.2)

Relevant Packages: @cloudflare/next-on-pages: 1.13.2 vercel: 37.1.0 next: 14.2.5

Description

Observed behavior

Recently our team have been having issues moving more pages from SSR to static generation with our Next.js setup. We have 1256 static pages at the moment and 24 edge function routes. The static routes are all output to .next/prerender-manifest.json (this is normal Next.js behaviour).

npx wrangler pages deploy copies the contents of the prerender-manifest.json file into each edge function js file as a __PRERENDER_MANIFEST variable. This duplication pushes us over the 25MiB limit for an individual file. Our prerender-manifest.json comes in at 781KiB, so for me we've got it duplicated 24 times and in theory only need 1 copy of this in the final _worker.js that's generated when executing npx wrangler pages deploy.

Has anyone else come across this before? Is this intended behaviour or can the duplication be reduced? Should I raise this instead or as well on https://github.com/cloudflare/workers-sdk?

Expected behavior

A shared __PRERENDER_MANIFEST variable in the final _workers.js

Reproduction

  1. Create a new Next.js app using the steps at Framework guides > Next.js > Full-stack (SSR) > Get started
  2. Add a new API route, e.g copy src/app/api/hello/route.ts to src/app/api/hi/route.ts
  3. npm run pages:build
  4. Inspect output in the following files, you'll see the duplication of a variable g.__PRERENDER_MANIFEST
    • .vercel/output/static/_worker.js/__next-on-pages-dist__/functions/api/hello.func.js
    • .vercel/output/static/_worker.js/__next-on-pages-dist__/functions/api/hi.func.js

Pages Deployment Method

Direct Upload (wrangler pages publish or the @cloudflare/pages-action GitHub Action)

Pages Deployment ID

No response

Additional Information

No response

Would you like to help?