fix: #556 guard against undefined window in getScroll#567
Conversation
|
Someone is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough在 ChangesgetScroll 空值防护与 offset 测试
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/util.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. tests/util.spec.tsxESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. 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 adds a runtime guard to the getScroll function in src/util.ts to handle cases where the window object is falsy. The review feedback correctly suggests updating the TypeScript signature of getScroll to accept Window | null | undefined to prevent compilation errors under strictNullChecks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/util.ts`:
- Around line 11-12: The getScroll function's runtime guard shows w can be
null/undefined but its signature is non-null Window; change the parameter type
of getScroll to accept Window | null | undefined (e.g., getScroll(w: Window |
null | undefined, top?: boolean): number) so the type reflects the runtime
check, and update any call sites (such as where you do const w = doc.defaultView
|| doc.parentWindow; pos.left += getScroll(w)) if necessary to satisfy
TypeScript or overloads.
- Line 12: 为覆盖 getScroll 中的空值保护分支,新增单测到 tests/util.spec.tsx:构造一个元素上下文使
ownerDocument.defaultView 和 ownerDocument.parentWindow 为 null/undefined(例如通过创建一个
mock document 或手动设置 element.ownerDocument.defaultView = undefined /
ownerDocument.parentWindow = null),然后调用 offset(element) 并断言返回值为 { left: 0, top:
0 };请在测试中同时验证 defaultView 缺失和 parentWindow 缺失两种情况以确保 getScroll 中的 if (!w) return
0 分支被覆盖(定位到 util.ts 中的 getScroll 和 offset 函数)。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Cover offset() when defaultView and parentWindow are missing or null. Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #567 +/- ##
==========================================
+ Coverage 98.93% 98.94% +0.01%
==========================================
Files 8 8
Lines 188 190 +2
Branches 68 69 +1
==========================================
+ Hits 186 188 +2
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
#566
Summary by CodeRabbit
Bug Fixes
Tests