Skip to content

fix: guard against null closable in Panel - #594

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
mokshupadhyay:fix/closable-null-crash
Dec 1, 2026
Merged

yoyo837 merged 1 commit into
react-component:masterfrom
mokshupadhyay:fix/closable-null-crash

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

<Dialog closable={null} /> throws TypeError: Cannot read properties of null (reading 'disabled') while rendering, because Panel decides whether the close button is disabled with typeof closable === 'object' && closable.disabled, and typeof null is 'object'. A null closable is not in the declared type, but a plain-JS caller (or a value that comes from props, such as closable={config?.closable ?? null}) can pass one, and the rest of the component already treats it like undefined: no close button.

The check is now typeof closable === 'object' && closable !== null && closable.disabled, the same null guard that closableObj already uses ten lines above (typeof closable === 'object' && closable !== null), so the file now treats null the same way in both places.

Test: should not crash and not display closeIcon when closable is null fails on master with the TypeError above and passes now. npm test (6 suites, 61 passed, 1 skipped as before), npm run tsc and npm run lint (0 errors) pass.

@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

@mokshupadhyay is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

当 closable 为 null 时,Panel 不再将其作为对象读取 disabled 属性。新增测试验证对话框仍会渲染,且不显示关闭按钮。

Changes

null closable 处理

Layer / File(s) Summary
关闭状态判断与渲染测试
src/Dialog/Content/Panel.tsx, tests/index.spec.tsx
Panel 在读取 closable.disabled 前检查 closable 不为 null。新增测试验证 closable={null} 时对话框存在且关闭按钮不存在。

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested reviewers: thinkasany

Merge Risk: Minimal · up to d8386

This fixes a render-time crash when a caller passes closable={null} to Dialog. Behavior for other values is unchanged, and the added test covers the null case. The merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed PR 标题 “fix: guard against null closable in Panel” 描述了主要变更。变更将 Panel 中的 closable 检查排除 null,避免 closable={null} 时出现 TypeError。标题具体、简洁,并指出了受影响的组件和问题。
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.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

小兔看见空值来,
关闭状态先检查。
对话框安稳出现,
关闭图标不再来。
测试轻轻点个头,
胡萝卜旁蹦起来。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4f0c7ed-fd1f-4713-91ae-5d5adb53ddcb
Commits

Reviewing files that changed from the base of the PR and between e2b50c3 and d838684.

Files selected for processing: 2

  • src/Dialog/Content/Panel.tsx
  • tests/index.spec.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.95%. Comparing base (e2b50c3) to head (d838684).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #594   +/-   ##
=======================================
  Coverage   98.95%   98.95%           
=======================================
  Files           8        8           
  Lines         192      192           
  Branches       69       69           
=======================================
  Hits          190      190           
  Misses          2        2           

☔ View full report in Codecov by Harness.
📢 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.

@yoyo837
yoyo837 merged commit a414ab9 into react-component:master Dec 1, 2026
11 of 12 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.

2 participants