SolidJS: warning "Missing attribute name 'data-index={index}' on measured element."
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- typescript
- 领域
- frontend, performance
调研方向
从链接的 CodeSandbox 复现开始,检查 SolidJS 对 virtualizer.measureElement 的使用,尤其是 issue 中显示的 data-index 和 ref 属性。跟踪测量回调如何读取元素,并将其与先分配 el.dataset.index 的变通方案进行比较。当复现不再发出缺少属性的警告,同时测量仍能正常工作时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Looks like virtualizer.measureElement is not working with SolidJS
<For each={virtualizer.getVirtualItems()}>{(item) =>
<div
class={item.index % 2 ? 'ListItemOdd' : 'ListItemEven'}
data-index={item.index}
ref={virtualizer.measureElement}
style={{
border: "1px solid red",
"box-sizing": "border-box",
"height": "150px"
}}
>
Row {item.index}
</div>
}</For>
Dirty workaround:
<For each={virtualizer.getVirtualItems()}>{(item) =>
<div
class={item.index % 2 ? 'ListItemOdd' : 'ListItemEven'}
data-index={item.index}
ref={(el) => {
el.dataset.index = item.index.toString(); // <--- see this!
virtualizer.measureElement(el);
}}
style={{
border: "1px solid red",
"box-sizing": "border-box",
"height": "150px"
}}
>
Row {item.index} {Date.now()}
</div>
}</For>
Your minimal, reproducible example
https://codesandbox.io/p/devbox/9rkhxf
Steps to reproduce
Just add
data-index={item.index}
ref={virtualizer.measureElement}
Expected behavior
No warning
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Chromium 133.0.6943.98
tanstack-virtual version
3.13.0
TypeScript version
No response
Additional context
No response
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- 主要语言
- TypeScript
- 星标
- 7.1k
- 派生
- 466
- 平均合并
- 2 天 31 分钟
- 30 天内合并 PR
- 13
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/virtual 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 38/100
-
难度 4/5 3-5 天 新手友好度 62/100
-
难度 4/5 3-5 天 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 68/100
相似的 Issue
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 1/5 1 小时以内 新手友好度 85/100
-
Mend: dependency security vulnerability untriaged
难度 2/5 1-3 小时 新手友好度 70/100