Skip to content

[codex] fix src TypeScript errors#43

Merged
zombieJ merged 2 commits into
masterfrom
codex/fix-src-ts-errors
May 15, 2026
Merged

[codex] fix src TypeScript errors#43
zombieJ merged 2 commits into
masterfrom
codex/fix-src-ts-errors

Conversation

@zombieJ
Copy link
Copy Markdown
Member

@zombieJ zombieJ commented May 15, 2026

Summary

  • Replace the removed onEndReached path with direct onScroll typing and exports.
  • Tighten src TypeScript boundaries around rowKey, grouped header rendering, nullable refs, and sticky header container handling.
  • Update docs/examples for the new scroll behavior.

Validation

  • npm run compile
  • npm test -- --runInBand

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Walkthrough

该 PR 将 Listy 组件的滚动末尾检测机制从自动触发的 onEndReached 改为由调用方在 onScroll 事件中手动实现。核心变更包括:删除 useOnEndReached hook,添加 onScroll 属性,更新组件内滚动事件处理,以及对应的示例和测试更新。

Changes

Scroll API 迁移

Layer / File(s) Summary
接口契约与类型更新
src/interface.ts, src/hooks/useStickyGroupHeader.tsx
ListyProps 新增 onScroll?: React.UIEventHandler<HTMLElement> 属性;StickyHeaderParamscontainerReflistRef 类型更新为可为 null
核心列表组件滚动逻辑重构
src/List.tsx
移除 useOnEndReached 导入和依赖,将 propsonEndReached 改为 onScroll,直接将用户的滚动事件处理器透传给 VirtualList,同时重新组织了导入、数据初始化和渲染逻辑的分区。
粘性头部空值安全性调整
src/hooks/useStickyGroupHeader.tsx
extraRender 回调中对 containerRef.current 进行显式空值检查,并改进滚动位置的默认值处理。
Hook 导出整理
src/hooks/index.ts
从导出列表中移除 useOnEndReached,仅保留 useGroupSegmentsuseStickyGroupHeaderuseFlattenRows
示例应用迁移到 onScroll
docs/examples/endless-scrolling.tsx
handleScroll 回调替代 onEndReached,在 onScroll 事件处理器中检测滚动位置,当到达底部时触发 loadMore
测试用例替换
tests/onScroll.test.tsx
新增测试验证 onScroll 事件转发和末尾检测行为,移除旧的 onEndReached 测试文件。
文档和配置更新
README.md, .prettierrc
将 API 文档表从 HTML 迁移为 Markdown 格式,移除 onEndReached 文档条目,添加 prefixCls 条目;Prettier 配置中针对 Markdown 文件启用 requirePragma 选项。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • react-component/listy#17: 该 PR 的核心逆向操作——之前引入了 useOnEndReached 机制,而本 PR 则完整移除这一机制,改为基于 onScroll 事件的用户侧实现模式。

Poem

🐰 从末尾自动弹,到滚动手动控,
事件透传更灵活,
Hook 卸载代码爽!
粘性头部也适配,
测试转身焕新生。✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive 标题"[codex] fix src TypeScript errors"是通用且宽泛的,未清楚反映PR的主要变更内容。PR的核心是用onScroll替换onEndReached并调整文档与示例,但标题只笼统指向"修复TypeScript错误"。 建议标题更明确地反映主要变更,如"Replace onEndReached with onScroll and tighten TypeScript types",以便更清晰地传达变更的具体内容。
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-src-ts-errors

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.37%. Comparing base (5b03506) to head (7a8dfb0).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/List.tsx 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
- Coverage   98.70%   96.37%   -2.33%     
==========================================
  Files           6        5       -1     
  Lines         154      138      -16     
  Branches       38       39       +1     
==========================================
- Hits          152      133      -19     
- Misses          2        5       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the onEndReached prop with a generic onScroll event handler, delegating the logic for detecting the end of a list to the consumer. Key changes include the removal of the useOnEndReached hook, updates to the Listy component and its documentation, and the addition of tests for scroll event forwarding. Internal improvements were also made, such as adding null checks in useStickyGroupHeader and renderHeaderRow. Feedback suggests addressing a potential race condition in the endless scrolling example's handleScroll function to prevent redundant data fetches.

Comment on lines +50 to +59
const handleScroll = useCallback<React.UIEventHandler<HTMLElement>>(
(event) => {
const { scrollTop, clientHeight, scrollHeight } = event.currentTarget;

if (scrollHeight - (scrollTop + clientHeight) <= 0) {
loadMore();
}
},
[loadMore],
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The handleScroll implementation for endless scrolling is susceptible to race conditions. Because React state updates are asynchronous and batched, multiple scroll events can trigger loadMore before the loading state is updated and the component re-renders. This can result in multiple redundant data fetches if the user continues to scroll at the bottom.

Consider using a useRef to track the scrollHeight that last triggered a load, ensuring loadMore is only called once per 'page' of content, or ensuring the loading check is resilient to rapid event firing.

@zombieJ zombieJ marked this pull request as ready for review May 15, 2026 07:52
@zombieJ zombieJ merged commit 12ce58b into master May 15, 2026
6 of 8 checks passed
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