fix(not-found): 改 Server Component 修 Server Action 路径下 useTranslations 崩溃#321
Merged
longsizhuo merged 1 commit intomainfrom Apr 26, 2026
Merged
fix(not-found): 改 Server Component 修 Server Action 路径下 useTranslations 崩溃#321longsizhuo merged 1 commit intomainfrom
longsizhuo merged 1 commit intomainfrom
Conversation
…s 崩溃 爬虫向 / POST 时 Next 走 Server Action 路径,未匹配到 action 后渲染 not-found.tsx 不经过 root layout,NextIntlClientProvider 不在 React 树里, useTranslations 抛 "No intl context" 直接 500 上报 Sentry。 改用 next-intl/server 的 getTranslations,绕开 client provider 依赖。 umami 埋点拆到 not-found-tracker.tsx 作为 client 子组件挂载。 Sentry: SENTRY-BOLE-NOTEBOOK-2
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 修复生产环境在 Server Action 路径(例如爬虫对 / 发起 POST)触发 not-found 渲染时,因未经过 root layout 导致 NextIntlClientProvider 缺失,从而 useTranslations 报 “No intl context” 的 500/Sentry 噪声问题。
Changes:
- 将
app/not-found.tsx改为 Server Component,用next-intl/server的getTranslations获取文案,避免依赖 client provider。 - 将原先依赖
useEffect/usePathname/window.umami的 404 埋点逻辑拆分为独立的 client 子组件app/not-found-tracker.tsx并在 404 页挂载。
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app/not-found.tsx | 改为服务端获取 i18n 文案并渲染 404,同时挂载 client 追踪子组件以避免 Server Action 场景下的 intl context 崩溃 |
| app/not-found-tracker.tsx | 承载 Umami 404 埋点(client-only hooks 与 window 访问),与 Server Component 解耦 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Sentry [SENTRY-BOLE-NOTEBOOK-2] —— prod 环境 `POST /` 请求触发 not-found 渲染时 `useTranslations` 抛 "No intl context",500 上报 Sentry。
根因
修复
影响
Test plan