Hydration hint false positive: `class=""` appears on dynamic components with an undefined class
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- nuxt, typescript
调研方向
先阅读 normalizeHTMLForComparison 的实现,以及针对 issue #351 和 #352 的现有回归测试;issue 指明该规范化步骤是修改点。复现动态组件中 class 未定义的情况,并比较 hydration 前后的 HTML。完成标准是:空的 class 和 style 属性在比较前被规范化,且此情况不再产生误报。
由索引模型根据 Issue 内容生成。
描述
Environment
- nuxt 4.6.2 (SSR, dev mode)
- @nuxt/hints 1.1.5
- vue 3.5.44
- @nuxt/ui 4.12.0 (where I first hit it; not needed to reproduce)
- Node.js 26.13.0, Windows 11
Reproduction
A component on any SSR page, components/EmptyClass.vue:
<script setup lang="ts">
const tag = ref('div')
const noClass = undefined
</script>
<template>
<component :is="tag" :class="noClass">
content
</component>
</template>
The same happens with Nuxt UI's <UForm> without a class prop: its root is a <component :is> and its computed class is undefined.
Describe the bug
@nuxt/hints warns about a hydration difference whose only content is an empty class attribute:
- <div>
+ <div class="">
Vue itself reports no hydration mismatch.
Controls I tried:
- the same with
:class="''": the server also rendersclass="", no warning; - a plain
<div :class="noClass">: neither side has the attribute, no warning.
Why it happens:
- SSR renders an undefined class as no attribute.
- On the client, the compiled render wraps the binding in
normalizeClass(), which turnsundefinedinto''. - Because the element is a dynamic component,
classis among the vnode'sdynamicProps, andhydrateElementpatches every dynamic prop during hydration. patchClass(el, '')then setsel.className = '', which createsclass="".- Vue's own
propHasMismatchtreats a missing class as"", so it sees no mismatch. useHydrationCheckcompares rawouterHTMLand only normalizesstyle.
Expected: no warning, since class="" and no class attribute are equivalent (and Vue agrees).
Suggestion: extend the normalization from #352 and drop empty class="" (and style="") attributes in normalizeHTMLForComparison before comparing.
Additional context
Same class of false positive as #351 (fixed in #352 for style serialization), and a concrete case of "make attribute comparison more precise" in #257.
Logs
[hydration] Component EmptyClass at .../components/EmptyClass.vue seems to have different html pre and post-hydration. Please make sure you don't have any hydration issue.
- 主要语言
- TypeScript
- 星标
- 347
- 派生
- 15
- 平均合并
- 7 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nuxt/hints 的其他 Issue
-
Hydration hint of a component with no name is rejected (400 Invalid payload) and surfaces as an unhandled error可能已有人在做 @lafllamme 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/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
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
[Bug]: Search input loses focus while typing on the Inventory, Reservations and Locations lists (view_configurations enabled)可能已有人在做 @medusa-os-bot 今天认领。 未关闭status: needs triaging type: bug version: 2.0
难度 2/5 1-3 小时 新手友好度 86/100
medusajs/medusa#17886 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 95/100
marimo-team/marimo#11949 ·
维护者通常 1 天内回复
-
bug server-time v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/servers#5559 ·
维护者通常 1 天内回复
-
D1 Time Travel restore help advertises 30 days without a plan qualifier可能已有人在做 @akhil9tiet 今天认领。 未关闭bug package:wrangler product:d1
难度 1/5 1-3 小时 新手友好度 78/100
cloudflare/workers-sdk#17000 · 2 条评论 ·
维护者通常 1 天内回复