Hydration hint of a component with no name is rejected (400 Invalid payload) and surfaces as an unhandled error

未关闭 适合新手
#410 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@lafllamme 已经在做这个了。

开始于 2026年11月12日。

  • #411 来自 @lafllamme —— 未关闭

评估

难度
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) sends componentName: undefined. I logged the rejected body: componentName is undefined, fileLocation is the page path, both HTML fields are strings.
  • The server handler rejects it: assertPayload requires typeof 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' when name, displayName and __name are all missing;
  • and/or add a .catch to 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nuxt/hints 的其他 Issue

查看 nuxt/hints 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。