vercel / vercel/next.js

Next.js bundles libraries only used in Server Components into the Client Bundle Chunks

Open
#68,972 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug SWC
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/phryneas/apollo-client-nextjs-reproduction-341

To Reproduce

The reproduction is a blank create repo created with yarn create next-app - all differences to a new repo are in this commit

  1. npm install
  2. npm run build
  3. grep -rl watchQuery .next/static/chunks -> .next/static/chunks/959-17277ce4ae2a5d3b.js (watchQuery is an Apollo Client api, so it's easily identifiable by that even when class names are mangled)
  4. npm run start
  5. open http://localhost:3000 in the browser
  6. verify that 959-17277ce4ae2a5d3b.js is indeed sent to the browser
Current vs. Expected behavior

Apollo Client should not end up in the Client Chunks when only referenced from Server Components.

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.6.0
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 14.2.5 // Latest available version is detected (14.2.5).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

SWC

Which stage(s) are affected? (Select all that apply)

next build (local), next start (local)

Additional context

This was brought to our attention in https://github.com/apollographql/apollo-client-nextjs/issues/341

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and run npm install followed by npm run build. Use grep -rl watchQuery .next/static/chunks to identify the unexpected client chunk, then run npm start and verify it is served in the browser. Done means libraries referenced only by Server Components no longer appear in or get sent as client chunks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
build-system, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.