@clerk/nextjs: Pages Router builds bundle next/headers into the client via the App Router provider
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- nextjs, react, typescript
- 领域
- build-system, frontend
调研方向
Start with the import chain: dist/esm/client-boundary/ClerkProvider.js loads both the App Router and Pages Router providers, and app-router/server-actions.js is a "use server" file that imports cookies from next/headers. Build a minimal Pages Router app with ClerkProvider in pages/_app, run next build, and search .next/static/chunks for RequestCookiesAdapter. Done means the client chunks no longer contain next/headers, and the App Router path still works. The maintainers have not chosen between an opt-in entry point and lazy loading, so confirm the approach first.
由索引模型根据 Issue 内容生成。
描述
This issue was written by Claude Code, but verified by me.
Reproduction
No separate repo. It shows up in any Pages Router app that renders ClerkProvider from @clerk/nextjs: build it and search the client chunks for Next's cookie code (e.g. RequestCookiesAdapter).
Publishable key
N/A. The problem is in the build output, not the instance.
Description
In a Pages Router app, ClerkProvider adds Next's server request code to every route's client JS: cookies, headers, draft mode and the edge cookie parser. In our app that's 18.5 KB gzipped per route.
The import chain, in @clerk/nextjs 7.4.3:
dist/esm/client-boundary/ClerkProvider.jsimports bothapp-router/client/ClerkProviderandpages/ClerkProvider, and picks one at runtime withnext/compat/router. Both are bundled.app-router/client/ClerkProvider.jsimportsinvalidateCacheActionfromapp-router/server-actions.js.server-actions.jsis a"use server"file that importscookiesfromnext/headers.
An App Router build turns that file into a server-action reference. A Pages Router build has no server-action boundary, so the file and the whole next/headers graph land in the client bundle.
Steps to reproduce:
- Create a Pages Router app with
ClerkProviderinpages/_app.tsx. - Run
next build. - Search
.next/static/chunksforRequestCookiesAdapterorResponseCookies.
Expected behavior:
A Pages Router app's client bundle doesn't include next/headers.
Actual behavior:
Every route's client bundle includes next/headers and the request code behind it.
Workaround:
We alias next/headers to a stub in the browser only:
// next.config.ts
turbopack: {
resolveAlias: {
'next/headers': { browser: './src/utils/next-headers-browser.ts' },
},
},
The stub exports cookies, headers and draftMode, each of which throws if called. Nothing calls them, since the App Router provider never renders under the Pages Router.
Possible fixes:
Bundling both providers makes sense for apps that mix routers. For Pages-only apps, either of these would avoid it:
- An opt-in Pages Router entry point that doesn't import the App Router provider.
- Load the App Router provider, or just
invalidateCacheAction, lazily, so a Pages Router build doesn't pull innext/headers.
Environment
System:
OS: macOS 26.6.2
CPU: (12) arm64 Apple M2 Pro
Binaries:
Node: 24.15.0
pnpm: 12.16.1
npmPackages:
@clerk/nextjs: ^7.4.3 => 7.4.3
@clerk/shared: ^4.15.0 => 4.15.0
next: 16.4.2 => 16.4.2
react: 19.2.6 => 19.2.6
react-dom: 19.2.6 => 19.2.6
Bundler: Turbopack (next build)
- 主要语言
- TypeScript
- 星标
- 1.8k
- 派生
- 492
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 374
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
clerk/javascript 的其他 Issue
-
<SignIn />: the reset password code step renders an empty, focusable back button with no accessible name可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
clerk/javascript#10708 ·
维护者通常 1 天内回复
-
Built-in reverification dialog lacks an accessible name (aria-dialog-name)可能已有人在做 @ItsShivam05 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
clerk/javascript#10548 ·
维护者通常 1 天内回复
-
MFA enrollment QR SVG lacks an accessible name (svg-img-alt)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
clerk/javascript#10547 ·
维护者通常 1 天内回复
-
<SignIn />: first "Use email" click switches back to phone when `initialValues.phoneNumber` is set可能已有人在做 @twicestruck 于 22 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
clerk/javascript#10487 ·
维护者通常 1 天内回复
-
useLoadedIsomorphicClerk misses "ready" when a ClerkProvider remounts after clerk-js has loaded — <ClerkLoading> never resolves可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
clerk/javascript#10462 ·
维护者通常 1 天内回复
相似的 Issue
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)未关闭area: @angular/build
难度 2/5 1-3 小时 新手友好度 65/100
angular/angular-cli#34764 ·
维护者通常 1 天内回复
-
status/need-triage
难度 2/5 1-3 小时 新手友好度 76/100
google-gemini/gemini-cli#30384 · 1 条评论 ·
维护者通常 1 天内回复
-
P2
难度 1/5 1 小时以内 新手友好度 84/100
维护者通常 1 天内回复
-
bug ready-for-human
难度 2/5 1-3 小时 新手友好度 60/100
LucasSantana-Dev/Lucky#3150 ·
维护者通常 1 天内回复
-
enhancement good first issue priority: low size: XS
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复