-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix(): render tabs eagerly #1474
Conversation
概述浏览在 变更
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
bricks/containers/src/tab/tab-group/index.tsx (1)
Line range hint
138-168
: 优化渲染时序和事件处理使用
useLayoutEffect
替代useEffect
是一个很好的改进,可以确保 DOM 更新的同步性。不过有以下几点建议:
- 类型转换可能不安全,建议添加类型检查
- 函数定义可以提取到 hook 外部以优化性能
建议按如下方式重构代码:
+ const handleSetActive = (e: MouseEvent) => { + const target = e.target; + if (!(target instanceof HTMLElement)) return; + const panel = (target as TabItem).panel; + if (panel) { + setActiveItem(panel); + onTabSelect?.(panel); + } + }; + const initSetTab = (navSlot: HTMLSlotElement) => { + const navSlotChildren = navSlot.assignedElements()[0] + ?.childNodes as unknown as TabItem[]; + if (!Array.isArray(navSlotChildren)) return; + navSlotChildren?.length > 0 && + setTabs(() => { + const tabs: string[] = []; + navSlotChildren.forEach((item) => tabs.push(item.panel)); + return tabs; + }); + }; useLayoutEffect(() => { const navSlot = navSlotRef.current; - initSetTab(); + initSetTab(navSlot); navSlot.addEventListener("click", handleSetActive); - navSlot.addEventListener("slotchange", initSetTab); + navSlot.addEventListener("slotchange", () => initSetTab(navSlot)); return () => { navSlot.removeEventListener("click", handleSetActive); - navSlot.removeEventListener("slotchange", initSetTab); + navSlot.removeEventListener("slotchange", () => initSetTab(navSlot)); }; }, [onTabSelect]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
bricks/containers/src/tab/tab-group/index.tsx
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build bricks (20.x)
- GitHub Check: Analyze (javascript-typescript)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1474 +/- ##
=======================================
Coverage 85.51% 85.51%
=======================================
Files 526 526
Lines 15762 15762
Branches 2381 2381
=======================================
Hits 13479 13479
Misses 1829 1829
Partials 454 454
|
🚀 Deployed on https://docs-preview-1474--next-bricks.netlify.app |
📐🤏 Size check result (b7c834e...5ec9acc): Load all bricks together
Critical changes: None. See full changes
Load bricks by each packageCritical changes: None. See full changes
Load by each brickCritical changes: None. See full changes
|
依赖检查
组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。
请勾选以下两组选项其中之一:
或者:
提交信息检查
Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。
破坏性变更:
feat
作为提交类型。BREAKING CHANGE: 你的变更说明
。新特性:
feat
作为提交类型。问题修复:
fix
作为提交类型。杂项工作:
即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:
chore
,docs
,test
等作为提交类型。Summary by CodeRabbit
useLayoutEffect
确保同步更新 DOM。