Skip to content

fix: look up tab nodes by data-node-key attribute without unescaped selector interpolation - #1031

Open
mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/escape-data-node-key-selector
Open

mokshupadhyay wants to merge 1 commit into
react-component:masterfrom
mokshupadhyay:fix/escape-data-node-key-selector

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Nov 30, 2026 •

Copy link
Copy Markdown

TabNavList measures the size of each tab by looking up its node with querySelector('[data-node-key="..."]'), with the key written into the selector after genDataNodeKey replaced only double quotes. A tab key that contains a backslash or a newline makes an invalid selector, and the tabs throw while measuring:

SyntaxError: '[data-node-key="line1
line2"]' is not a valid selector

(The same class of error as react-component/cascader#674, where option values with a backslash or newline broke a selector.) A key such as a Windows path (C:\files) or a value that came from user data reaches this.

The measurement now reads the data-node-key attribute of the nodes once into a Map and looks each tab up by genDataNodeKey(key), so no selector is built from keys. TabNode still writes data-node-key={genDataNodeKey(key)}, so both sides use the same value.

Test: key contains backslash or newline should not crash and still measures tab size in tests/index.test.tsx fails on master with the SyntaxError above and passes now. npm test (6 suites, 112 tests), npm run tsc, npm run lint (0 errors) and prettier on the changed files pass.

Summary by CodeRabbit

  • Bug Fixes
    • 修复标签标识包含反斜杠、末尾反斜杠或换行符时,活动标签下方的指示条宽度显示不准确的问题。页面渲染及切换活动标签后,指示条均能正确显示宽度。

@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

@mokshupadhyay is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

标签尺寸更新改用节点键映射查找对应节点,不再为每个标签单独构造选择器并查询。新增回归测试,覆盖含反斜杠或换行符的标签键及其 ink bar 宽度。

Changes

标签尺寸查询

层 / 文件 摘要
节点键映射与特殊键回归测试
src/TabNavList/index.tsx, tests/index.test.tsx
updateTabSizes 遍历带有 data-node-key 的节点,并为每个非空键保留首个节点。尺寸收集按生成的节点键获取节点。测试覆盖 Windows 路径、末尾反斜杠和含换行符的标签键,并断言 ink bar 宽度为 20px。

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: zombiej

Merge Risk: Minimal · up to a8544

This change fixes a crash during tab measurement for tab keys containing backslashes or newlines. It adds a regression test and has no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题描述了 TabNavList 中的主要修复:不再通过未转义的选择器插值查找标签节点,而是按 data-node-key 属性查找。这与变更摘要一致:先遍历 [data-node-key] 节点建立映射,再按键读取尺寸,并新增了反斜杠和换行符键的测试。标题简洁,指出了核心改动。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

兔子轻敲标签栏,
节点映射排成行。
反斜杠键不迷路,
换行标签也测量。
Ink bar 宽二十像,
兔耳摇摇庆修好。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f5f048c4-364f-4c0d-b290-1f3cfc4b35ab
Commits

Reviewing files that changed from the base of the PR and between 822d74d and a854427.

Files selected for processing: 2

  • src/TabNavList/index.tsx
  • tests/index.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant