[codex] support function scroll offset#358
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Walkthrough新增可函数化的 ScrollOffset(支持 number | (info) => number);useScrollTo 接收 getSize 并在解析 offset 时调用;List 提前计算并传入 getSize;更新导出并添加测试覆盖函数式 offset 行为与 NaN 回退。 变更内容动态滚动偏移功能
Sequence DiagramsequenceDiagram
participant Consumer
participant List
participant useGetSize
participant useScrollTo
participant DOM_ul
Consumer->>List: 调用 scrollTo(target with offset)
List->>useGetSize: 计算 getSize
List->>useScrollTo: 传入 getSize 调用 useScrollTo
useScrollTo->>useScrollTo: 若 offset 为函数,调用 offset({ getSize }) 得到数值
useScrollTo->>DOM_ul: 设置 ul.scrollTop
预估审查工作量🎯 3 (Moderate) | ⏱️ ~20 分钟 建议审查者
彩蛋诗
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces support for functional offsets in the scrollTo method, allowing developers to calculate scroll offsets dynamically using getSize information. The implementation updates the ScrollTarget type and the useScrollTo hook to handle these functional offsets. My feedback highlights that the current implementation evaluates the offset function only once, which may lead to stale values during the multi-pass scroll synchronization process. I have suggested ensuring the result is always a valid number to prevent potential issues with NaN values.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #358 +/- ##
==========================================
+ Coverage 97.48% 97.50% +0.01%
==========================================
Files 19 19
Lines 796 800 +4
Branches 189 191 +2
==========================================
+ Hits 776 780 +4
Misses 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b43683c to
8cf8b44
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/hooks/useScrollTo.tsx`:
- Around line 185-186: The code sets offset from arg.rawOffset (possibly a
function) without runtime numeric validation, so if the callback returns
undefined/NaN an invalid value will be stored in syncState.offset; update the
assignment to validate the computed value (use Number.isFinite or similar) and
fall back to a safe default (e.g., 0) before writing into state: when computing
offset from rawOffset({ getSize }), check that the result is a finite number and
otherwise use the fallback so syncState.offset always receives a valid numeric
value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 33a1ed69-f3f1-4a7f-bd88-ed643b6826f9
📒 Files selected for processing (4)
src/List.tsxsrc/hooks/useScrollTo.tsxsrc/index.tstests/scroll.test.js
8cf8b44 to
ba1fd3d
Compare
|
@gemini-code-assist CR again |
There was a problem hiding this comment.
Code Review
This pull request enhances the scrollTo functionality by allowing the offset property to be a function that receives a getSize utility, enabling dynamic offset calculations based on item sizes. The implementation includes updates to the ScrollOffset type, a new getOffset helper to resolve functional offsets with a fallback for invalid values, and comprehensive unit tests for these new capabilities. I have no feedback to provide.
Summary
scrollTo({ offset })to receive a function.getSizeinto the offset function so callers can derive dynamic offsets from measured item ranges.ScrollOffsetandScrollOffsetInfotypes.Validation
npm run lintbunx tsc --noEmitnpm run compilebun run test -- --coverage --silentSummary by CodeRabbit
新功能
修复
测试