Repository navigation
fix: find the scrollTo row by key without building a CSS selector - #1528
mokshupadhyay wants to merge 1 commit into
Conversation
scrollTo({ key }) and scrollTo({ index }) looked the row up with querySelector('[data-row-key="${key}"]'). A row key with a double quote or a newline threw SyntaxError: Invalid selector, and a key with a backslash silently matched nothing. Compare the data-row-key attribute instead.
|
@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. |
|
No actionable comments were generated in the recent review. Walkthrough
Changes行键滚动定位
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
ref.scrollTo({ key })(andscrollTo({ index }), which turns the index into a row key) finds the row withquerySelector('[data-row-key="${mergedKey}"]'), with the key written into the selector as it is. A row key that contains a double quote or a newline makes an invalid selector andscrollTothrows, and a key with a backslash silently matches no row:Row keys come from data (file names, paths, ids), so this is reachable with the documented
scrollToAPI. It is the same class of bug as react-component/cascader#674, tabs#1031 and menu#907.scrollTonow takes the[data-row-key]nodes of the body and picks the one whose attribute equalsString(mergedKey), so no selector is built from keys.BodyRowwritesdata-row-key={rowKey}, which React stringifies, so the comparison matches what was rendered.Test:
support scrollTo key with special charactersintests/refs.spec.tsxfails onmaster(theSyntaxErrorabove, andexpected nullfor the backslash key) and passes now.npx vitest run(21 files, 239 tests),tsc --noEmit, eslint (0 errors; 6 warnings that are also there without this change) and prettier on the changed files pass.Summary by CodeRabbit