Skip to content

Conversation

HellowVirgil
Copy link

@HellowVirgil HellowVirgil commented Aug 13, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background

image image

bar.view.tsx throw error Uncaught TypeError: Cannot read properties of undefined.

Cause

  • The useMemo hook uses keybindingRegistry variable to generate title
  • However, the dependency array only includes [component], missing keybindingRegistry
  • When React performs dependency comparison, the areHookInputsEqual function attempts to read incomplete dependency array, resulting in accessing undefined's length property

Solution

Add keybindingRegistry to the dependency array of useMemo.

Summary by CodeRabbit

  • Bug Fixes
    • 修复标签栏标题在组件为空时可能报错的问题(避免访问不可用数据导致异常)。
    • 修复快捷键映射变更后标签标题中加速键提示未及时更新的问题,现会随快捷键配置变化实时刷新。
    • 不涉及对外接口或行为变更,仅提升可见性与一致性。

@CLAassistant
Copy link

CLAassistant commented Aug 13, 2025

CLA assistant check
All committers have signed the CLA.

@opensumi opensumi bot added the 🐞 bug Something isn't working label Aug 13, 2025
Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Walkthrough

将 IconTabView 中用于计算标题的 useMemo 增加空值保护并将依赖从 [component] 扩展为 [component, keybindingRegistry],使包含激活快捷键提示的标题在 keybindingRegistry 变化时会重新计算。无其他逻辑或公开 API 变更。

Changes

Cohort / File(s) Summary
Tab bar view
packages/main-layout/src/browser/tabbar/bar.view.tsx
在 IconTabView 的 title 计算中增加对 component 的空值保护(返回空字符串),并把 useMemo 的依赖从 [component] 扩展为 [component, keybindingRegistry],以便在 keybindingRegistry 变化时重新计算标题;无其他改动。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 分钟

Possibly related PRs

Suggested reviewers

  • Ricbet

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5a61d9 and 0cac378.

📒 Files selected for processing (1)
  • packages/main-layout/src/browser/tabbar/bar.view.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/main-layout/src/browser/tabbar/bar.view.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
Contributor

@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

🔭 Outside diff range comments (3)
packages/main-layout/src/browser/tabbar/bar.view.tsx (3)

147-150: 避免在渲染阶段产生副作用:把 updateTabInMoreKey(true) 移入 useEffect

在 render 期间执行副作用(更新 service 状态)会带来难以预测的重复调用与顺序问题,且违反 React 约定。建议将其迁移到 useEffect,并以 hideContainers 为依赖。

建议改动(删除渲染期副作用):

-  hideContainers.forEach((componentInfo) => {
-    tabbarService.updateTabInMoreKey(componentInfo.options!.containerId, true);
-  });
+  // moved to useEffect to avoid side-effects during render

在组件内补充一个 effect(在合适位置添加,不必紧邻本行):

useEffect(() => {
  hideContainers.forEach((c) => {
    tabbarService.updateTabInMoreKey(c.options!.containerId, true);
  });
  visibleContainers.forEach((c) => {
    tabbarService.updateTabInMoreKey(c.options!.containerId, false);
  });
}, [hideContainers, visibleContainers, tabbarService]);

151-212: useCallback 依赖缺失导致闭包值陈旧

renderContainers 使用了 TabView、tabbarService、tabClassName、willHideTabbar、forbidCollapse 等外部变量,但依赖数组为空,可能导致点击/拖拽逻辑使用过期值(例如 willHideTabbar 或 forbidCollapse 变化后不生效)。

建议改动:

-  const renderContainers = useCallback(
+  const renderContainers = useCallback(
     (component: ComponentRegistryInfo, tabbarService: TabbarService, currentContainerId?: string, side?: string) => {
       // ...
     },
-    [],
+    [TabView, tabbarService, tabClassName, willHideTabbar, forbidCollapse],
   );

158-159: 同样避免在渲染阶段更新 service 状态

这里对可见项执行 updateTabInMoreKey(false) 也属于副作用,建议移除并交由上文建议的 useEffect 统一处理。

建议改动:

-      tabbarService.updateTabInMoreKey(containerId, false);
+      // moved to useEffect to avoid side-effects during render
🧹 Nitpick comments (1)
packages/main-layout/src/browser/tabbar/bar.view.tsx (1)

301-309: 拼写小问题:Elipses → Ellipses

纯展示组件命名建议修正拼写(不影响功能,但可读性更佳)。若对外有引用,请同步更新引用点。

建议改动(节选):

-export const IconElipses: FC = () => {
+export const IconEllipses: FC = () => {
  // ...
-export const TextElipses: FC = () => (
+export const TextEllipses: FC = () => (

引用处:

-        MoreTabView={IconElipses}
+        MoreTabView={IconEllipses}

-        MoreTabView={IconElipses}
+        MoreTabView={IconEllipses}

-        MoreTabView={TextElipses}
+        MoreTabView={TextEllipses}

-        MoreTabView={IconElipses}
+        MoreTabView={IconEllipses}

Also applies to: 311-318, 336-336, 381-381, 410-410, 432-432

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 872ebf6 and c5a61d9.

📒 Files selected for processing (1)
  • packages/main-layout/src/browser/tabbar/bar.view.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/main-layout/src/browser/tabbar/bar.view.tsx (1)
packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts (1)
  • keybindingRegistry (71-73)
🔇 Additional comments (2)
packages/main-layout/src/browser/tabbar/bar.view.tsx (2)

248-255: 修复正确:为 useMemo 补充 keybindingRegistry 依赖,避免崩溃与标题不刷新问题

该改动使标题在 keybindingRegistry 变更时能正确重新计算,同时避免 React 比较依赖时的异常。变更粒度小且定位精准,赞。


248-255: 确认 – 未发现其他缺失的 keybindingRegistry 依赖
已在全仓库范围内扫描所有 useMemo/useCallback 回调体中对 keybindingRegistry 的引用,未检测到未在依赖数组中声明的场景,可放心忽略此项风险。

@HellowVirgil HellowVirgil force-pushed the fix/icon-tab-view-use-memo-error branch from c5a61d9 to 0cac378 Compare August 13, 2025 13:32
Copy link
Member

@Ricbet Ricbet left a comment

Choose a reason for hiding this comment

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

LGTM

@Ricbet
Copy link
Member

Ricbet commented Aug 14, 2025

/next

@opensumi
Copy link
Contributor

opensumi bot commented Aug 14, 2025

🎉 PR Next publish successful!

3.9.1-next-1755164421.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants