Hydration hint of a component with no name is rejected (400 Invalid payload) and surfaces as an unhandled error
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- nuxt, typescript
调研方向
从 src/runtime/hydration/composables.ts 中 hydration 报告调用的位置,以及 src/runtime/hydration/handlers.ts 中 assertPayload 的位置开始。追踪未命名组件如何进入 payload,以及被拒绝的报告如何处理。完成标准是:能够为提供的仅含 template 的复现用例存储提示,并且失败的报告不会变成未处理错误;issue 没有指定要运行的测试文件。
由索引模型根据 Issue 内容生成。
描述
Environment
- nuxt 4.6.2 (SSR, dev mode)
- @nuxt/hints 1.1.5 (also checked against
main: same code) - vue 3.5.44
- Node.js 26.13.0, Windows 11
Reproduction
A page with no <script setup> (template only), whose HTML differs between server and client, pages/repro.vue:
<template>
<div>{{ Date.now() }}</div>
</template>
Open /repro in dev mode.
Describe the bug
The hydration hint for that page is never stored, and an unhandled error opens Nuxt's dev error overlay:
FetchError: [POST] "/__nuxt_hints/hydration": 400 Invalid payload
Why it happens (src/runtime/hydration/composables.ts):
componentName = instance.type.name ?? instance.type.displayName ?? instance.type.__name. A component with none of the three (a template-only SFC, which gets no__name) sendscomponentName: undefined. I logged the rejected body:componentNameisundefined,fileLocationis the page path, both HTML fields are strings.- The server handler rejects it:
assertPayloadrequirestypeof body.componentName === 'string'(src/runtime/hydration/handlers.ts). - The
$fetch(HYDRATION_ROUTE, …).then(…)call has no.catch, so the rejection becomes an unhandled error.
Side effect: the dev error overlay (nuxt-error-overlay) contains a <main>, so accessibility checks run on the page (axe landmark-no-duplicate-main) report two main landmarks.
Expected: the hint is stored and shown in the DevTools panel like the others, and a failed report does not surface as an unhandled error.
Suggestion:
- fall back to a name derived from
__file(e.g. the file's base name) or a placeholder like'Anonymous'whenname,displayNameand__nameare all missing; - and/or add a
.catchto the report call that logs a warning instead of throwing.
Additional context
Found while triaging the hydration hints of an app together with #409 (a different false positive in the same check).
Logs
FetchError: [POST] "/__nuxt_hints/hydration": 400 Invalid payload
at async $fetch2 (.../ofetch/dist/shared/ofetch.CWycOUEr.mjs:332:15)
- 主要语言
- TypeScript
- 星标
- 347
- 派生
- 15
- 平均合并
- 7 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nuxt/hints 的其他 Issue
-
Hydration hint false positive: `class=""` appears on dynamic components with an undefined class可能已有人在做 @lafllamme 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
need reproduction
难度 4/5 3-5 天 新手友好度 30/100
nuxt/hints#277 · 1 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
-
Make hydration diff more precise可能重新可做 @huang-julien 于 260 天前认领,目前没有进行中的 PR。 未关闭
nuxt/hints#257 · 1 条评论 · 2 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
-
Assets Hints for improved performance可能重新可做 @Baroshem 于 296 天前认领,目前没有进行中的 PR。 未关闭
nuxt/hints#199 · 3 条评论 · 2 个 reaction · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
bug priority: low role: BE stage: now
难度 2/5 1-3 小时 新手友好度 86/100
ahmadrosid/nakama#2594 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
milind-soni/OpenMausBot#6495 ·
维护者通常 1 天内回复
-
Navigating the session tree adds the branch's prompts to Up-arrow history again可能已有人在做 @acmerfight 今天认领。 未关闭untriaged
难度 2/5 1-3 小时 新手友好度 68/100
earendil-works/pi#12279 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
approved documentation
难度 1/5 1 小时以内 新手友好度 89/100
vitest-dev/vitest#12015 · 4 条评论 ·
维护者通常 1 天内回复