Skip to content

feat: Remove findDOMNode #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025
Merged

feat: Remove findDOMNode #216

merged 2 commits into from
Jan 23, 2025

Conversation

Zyf665
Copy link
Contributor

@Zyf665 Zyf665 commented Jan 18, 2025

Summary by CodeRabbit

发行说明

  • 依赖变更

    • rc-util 替换为 @rc-component/util
  • 功能调整

    • 移除 DomWrapper 组件
    • 更新 SingleObserver 组件的 DOM 处理方法
    • 简化组件渲染逻辑
  • 测试更新

    • 调整 ResizeObserver 组件的测试用例
    • 修改对无效引用的处理逻辑

这些变更旨在优化组件的性能和可靠性,同时保持核心功能不变。

Copy link

vercel bot commented Jan 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
resize-observer ❌ Failed (Inspect) Jan 22, 2025 11:00am

Copy link

coderabbitai bot commented Jan 18, 2025

总览

变更概述

这个拉取请求主要涉及从 rc-util 库迁移到 @rc-component/util 库,并对 ResizeObserver 组件进行了重构。变更包括依赖项更新、删除 DomWrapper 组件、调整 DOM 元素处理方法,以及相应地更新测试用例。

变更

文件 变更摘要
package.json 替换依赖:rc-util@rc-component/util
src/SingleObserver/DomWrapper.tsx 完全移除 DomWrapper 组件
src/SingleObserver/index.tsx 重构 DOM 元素处理方法,移除 getDom,新增 getDomElement
src/index.tsx 更新工具函数导入路径
tests/index.spec.js 调整 onResize 事件测试用例
tests/ref.spec.tsx 修改引用相关测试用例

序列图

sequenceDiagram
    participant Component as ResizeObserver
    participant Util as @rc-component/util
    participant DOM as DOM Element
    
    Component->>Util: 获取 DOM 元素
    Util-->>Component: 返回 DOM 元素
    Component->>DOM: 观察大小变化
    DOM-->>Component: 触发 resize 事件
Loading

诗歌

🐰 代码跳跃,依赖转换
工具库换新装
DOM 舞动,引用轻盈
重构魔法,兔子欢唱
技术之路,永不停歇 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

socket-security bot commented Jan 18, 2025

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher

View full report↗︎

findDOMNode<HTMLElement>(wrapperRef.current);
const getDomElement = () => {
return getDOM( elementRef.current ) as HTMLElement
}

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (93% of all statements in
the enclosing function
have an explicit semicolon).
Copy link

codecov bot commented Jan 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.93%. Comparing base (fb18ff2) to head (ce5e265).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
- Coverage   94.24%   93.93%   -0.31%     
==========================================
  Files           6        5       -1     
  Lines         139      132       -7     
  Branches       42       37       -5     
==========================================
- Hits          131      124       -7     
  Misses          7        7              
  Partials        1        1              

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

@zombieJ zombieJ self-assigned this Jan 22, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/index.spec.js (1)

237-237: 验证行为变更的断言正确

这个断言正确反映了移除 findDOMNode 后的预期行为,即对于非 ref-able 的组件不应触发 resize 事件。

不过建议添加一个相关的测试用例来验证错误处理:

+ it('should warn when child is not ref-able', () => {
+   const Wrapper = props => <>{props.children}</>;
+   mount(
+     <ResizeObserver>
+       <Wrapper>
+         <div />
+       </Wrapper>
+     </ResizeObserver>,
+   );
+   expect(errorSpy).toHaveBeenCalledWith(
+     expect.stringContaining('can not get DOM element'),
+   );
+ });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 795c486 and ce5e265.

📒 Files selected for processing (2)
  • tests/index.spec.js (2 hunks)
  • tests/ref.spec.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/ref.spec.tsx
🔇 Additional comments (1)
tests/index.spec.js (1)

Line range hint 222-236: 测试用例实现完整且清晰

测试用例通过简单的 Wrapper 组件很好地验证了 ResizeObserver 对非 ref-able 组件的处理行为。实现方式简洁明了。

@zombieJ zombieJ merged commit 6774b1e into react-component:master Jan 23, 2025
9 of 10 checks passed
@coderabbitai coderabbitai bot mentioned this pull request May 19, 2025
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.

2 participants