Skip to content

fix: resolve optional chain lint warnings#1905

Closed
meet-student wants to merge 5 commits into
ant-design:mainfrom
meet-student:codex/fix-optional-chain-lint
Closed

fix: resolve optional chain lint warnings#1905
meet-student wants to merge 5 commits into
ant-design:mainfrom
meet-student:codex/fix-optional-chain-lint

Conversation

@meet-student
Copy link
Copy Markdown
Member

@meet-student meet-student commented May 23, 2026

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

📝 Change Log

Language Changelog
🇺🇸 English resolve optional chain lint warnings
🇨🇳 Chinese -

Summary by CodeRabbit

  • Bug Fixes

    • 改进了聊天提供者在流式/异常数据下的容错与稳定性
    • 增强了文件预览、组件校验等场景的空值安全处理
  • Chores

    • 统一与简化了空值判断写法,显式处理数值类型以避免计算错误
  • Tests

    • 增强并调整了请求、流式响应与中止相关测试覆盖和用例实现

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

PR 统一应用可选链操作符简化多处空值检查,显式转换 Token 字体值为 Number 确保类型安全,改进流式聊天处理的错误处理策略(从记录改为静默),并扩展测试基础设施以支持持续挂起请求和中止场景测试。

Changes

可选链、数值转换与流式处理改进

Layer / File(s) Summary
可选链守卫条件简化
packages/x-card/src/A2UI/utils.ts, packages/x/.dumi/theme/common/ComponentChangelog/ComponentChangelog.tsx, packages/x/components/attachments/util.ts, packages/x/docs/x-markdown/demo/streaming/format.tsx, packages/x/docs/x-sdk/demos/chat-providers/custom-provider-width-ui.tsx
!catalog || !catalog.components 等显式双重检查改为 catalog?.components 等可选链,在验证、渲染和数据处理函数中简化提前返回逻辑。
Token 字体尺寸数值转换
packages/x/.dumi/pages/index/components/DesignGuide.tsx, packages/x/components/attachments/FileList/Progress.tsx
在 style 和 progress 计算前显式将 token.fontSizeHeading1token.fontSizeHeading2 转换为 Number(...),确保算术运算的类型安全。
流式数据处理改进
packages/x-sdk/src/chat-providers/OpenAIChatProvider.ts, packages/x-sdk/src/chat-providers/DeepSeekChatProvider.ts
使用可选链保护 responseHeaders?.get() 的访问;将 catch 块从捕获并记录错误改为静默忽略畸形流片段,保持累积的助手消息内容。
测试模拟和定时器改进
packages/x-sdk/src/chat-providers/__test__/providers.test.ts, packages/x-sdk/src/x-chat/__test__/index.test.tsx, packages/x-sdk/src/x-request/__test__/abort.test.ts, packages/x-sdk/src/x-request/__test__/index.test.ts, packages/x-sdk/tests/utils.tsx
更新期望值以支持新的静默错误处理;添加 requestNeverEnd 工具函数生成永不结束的 Promise;移除 jest-fetch-mock 依赖改为显式注入 fetch mock;在 waitFakeTimer 中调整微任务与 act 的相对时序。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

lgtm

Suggested reviewers

  • Div627

Poem

🐰 可选链闪闪发光,数值转换稳稳当当,
流式处理静悄悄,测试工具帮忙忙,
小改动心里暖,代码跑得更安稳!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确概括了主要变更内容,即解决可选链(optional chain)相关的lint警告。
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@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 refactors several files to use optional chaining for more concise null and undefined checks. The reviewer suggested further simplifying a condition in custom-provider-width-ui.tsx by removing redundant optional chaining in a logical OR expression where the object's existence is already verified by the preceding check.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Bundle Report

Bundle size has no change ✅

@meet-student meet-student force-pushed the codex/fix-optional-chain-lint branch from 0c2e025 to 2046652 Compare May 23, 2026 03:26
@meet-student meet-student force-pushed the codex/fix-optional-chain-lint branch 2 times, most recently from 348a84a to 5607322 Compare May 23, 2026 03:49
@meet-student meet-student changed the title 🐛 fix: resolve optional chain lint warnings fix: resolve optional chain lint warnings May 23, 2026
@meet-student meet-student force-pushed the codex/fix-optional-chain-lint branch from 5607322 to d0395b0 Compare May 23, 2026 04:02
Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
packages/x/components/attachments/FileList/Progress.tsx (1)

17-17: 💤 Low value

简化数值转换(避免不必要的 Number(...)

  • token.fontSizeHeading2 在该仓库主题类型中为 numberpackages/x/components/theme/interface/maps/font.ts),且在其他样式使用处也直接作为数值使用(如 packages/x/components/attachments/style/index.tspackages/x/.dumi/pages/index/components/DesignGuide.tsx),因此这里的 Number(token.fontSizeHeading2) * 2 属于冗余。
  • antdProgresstype="circle")的 size 支持 number,当前传入的数值类型是匹配的;除非能证明运行时会出现 undefined,不需要为了防御性再补 NaN fallback。

建议将 size={Number(token.fontSizeHeading2) * 2} 简化为 size={token.fontSizeHeading2 * 2} 以保持一致性。

🤖 Prompt for 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.

In `@packages/x/components/attachments/FileList/Progress.tsx` at line 17, The
expression size={Number(token.fontSizeHeading2) * 2} is redundant because
token.fontSizeHeading2 is already a number; update the Progress (type="circle")
usage to compute size directly as token.fontSizeHeading2 * 2 (remove
Number(...)) in the FileList/Progress component so it matches other usages and
avoids unnecessary conversion.
🤖 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 `@packages/x-sdk/src/chat-providers/OpenAIChatProvider.ts`:
- Around line 56-58: The empty catch in OpenAIChatProvider.transformMessage (and
DeepSeekChatProvider.transformMessage) swallows JSON.parse(chunk.data) errors
and makes them unobservable; update these catch blocks to report the error via a
configurable hook (e.g. new onTransformError option) or reuse
callbacks.onError/processLogger so parse failures are logged/counted (while
preserving the current behavior of not rolling back the assistant message), and
add a unit test that sends an invalid chunk.data and asserts the function
doesn't throw/rollback but does emit the observability event/counter.

---

Nitpick comments:
In `@packages/x/components/attachments/FileList/Progress.tsx`:
- Line 17: The expression size={Number(token.fontSizeHeading2) * 2} is redundant
because token.fontSizeHeading2 is already a number; update the Progress
(type="circle") usage to compute size directly as token.fontSizeHeading2 * 2
(remove Number(...)) in the FileList/Progress component so it matches other
usages and avoids unnecessary conversion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a4d9f820-039f-4930-a11f-62c33befc4df

📥 Commits

Reviewing files that changed from the base of the PR and between 5607322 and d0395b0.

⛔ Files ignored due to path filters (1)
  • packages/x-markdown/src/plugins/Latex/__tests__/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (14)
  • packages/x-card/src/A2UI/utils.ts
  • packages/x-sdk/src/chat-providers/DeepSeekChatProvider.ts
  • packages/x-sdk/src/chat-providers/OpenAIChatProvider.ts
  • packages/x-sdk/src/chat-providers/__test__/providers.test.ts
  • packages/x-sdk/src/x-chat/__test__/index.test.tsx
  • packages/x-sdk/src/x-request/__test__/abort.test.ts
  • packages/x-sdk/src/x-request/__test__/index.test.ts
  • packages/x-sdk/tests/utils.tsx
  • packages/x/.dumi/pages/index/components/DesignGuide.tsx
  • packages/x/.dumi/theme/common/ComponentChangelog/ComponentChangelog.tsx
  • packages/x/components/attachments/FileList/Progress.tsx
  • packages/x/components/attachments/util.ts
  • packages/x/docs/x-markdown/demo/streaming/format.tsx
  • packages/x/docs/x-sdk/demos/chat-providers/custom-provider-width-ui.tsx

Comment thread packages/x-sdk/src/chat-providers/OpenAIChatProvider.ts
@meet-student meet-student force-pushed the codex/fix-optional-chain-lint branch from 26ecc08 to 31dd293 Compare May 25, 2026 01:36
@meet-student meet-student force-pushed the codex/fix-optional-chain-lint branch from 31dd293 to ff88c3e Compare May 25, 2026 02:18
@afc163 afc163 enabled auto-merge (squash) May 25, 2026 02:24
auto-merge was automatically disabled June 4, 2026 08:15

Pull request was closed

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