Skip to content

fix: notFoundContent failed the search state#1201

Merged
zombieJ merged 3 commits intomasterfrom
fix-empty
Feb 5, 2026
Merged

fix: notFoundContent failed the search state#1201
zombieJ merged 3 commits intomasterfrom
fix-empty

Conversation

@zombieJ
Copy link
Member

@zombieJ zombieJ commented Feb 5, 2026

fix ant-design/ant-design#55968
fix ant-design/ant-design#56735

close #1199

Summary by CodeRabbit

发布说明

  • 改进

    • 优化选择器在打开/关闭及搜索交互时的内部状态处理,提升稳定性与输入体验。
  • 测试

    • 新增测试覆盖:在启用搜索且未找到结果时,输入与搜索回调仍能正常工作并保持响应。

zombieJ and others added 2 commits February 5, 2026 16:52
Return both ssrSafeOpen and mergedOpen to prevent incorrect
clearing of search text when mergedOpen differs from rawOpen.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
select Ready Ready Preview, Comment Feb 5, 2026 9:15am

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zombieJ, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a bug in the Select component where the search input behaved incorrectly when notFoundContent was set to null. The fix involves a refinement in how the component manages its open state, introducing a distinct 'raw' open state from the useOpen hook. This ensures that the search text is only cleared when the component is truly closed, allowing users to type freely even when no matching options are found and notFoundContent is intentionally suppressed, thereby improving the search experience.

Highlights

  • Refactor useOpen Hook: The useOpen hook's return signature has been updated to include an additional rawOpen state, which represents the SSR-safe open state, preceding the mergedOpen state.
  • Corrected Search State Cleanup Logic: The BaseSelect component now utilizes the newly introduced rawOpen state instead of mergedOpen within the useEffect hook responsible for clearing search text. This change ensures that the search input is not prematurely cleared when the dropdown closes, specifically addressing scenarios where notFoundContent is null.
  • New Test Case for notFoundContent: A new test has been added to Select.test.tsx to explicitly verify that typing functionality in the Select component remains active and correct when notFoundContent is set to null and no matching options are found during a search.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/BaseSelect/index.tsx
    • Updated the destructuring of the useOpen hook's return value to include rawOpen.
    • Modified the useEffect dependency for cleaning search text to use rawOpen instead of mergedOpen.
  • src/hooks/useOpen.ts
    • Changed the return type signature of the useOpen hook to include rawOpen (which is ssrSafeOpen) as the first element.
    • Adjusted the return statement to include ssrSafeOpen before mergedOpen.
  • tests/Select.test.tsx
    • Added a new test case to validate that typing in a Select component works as expected when notFoundContent is null and no options match the search.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.43%. Comparing base (818b07c) to head (b70d9c8).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1201   +/-   ##
=======================================
  Coverage   99.43%   99.43%           
=======================================
  Files          31       31           
  Lines        1230     1230           
  Branches      439      441    +2     
=======================================
  Hits         1223     1223           
  Misses          7        7           

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

将 useOpen 钩子返回值扩展为四元组以暴露新的 rawOpen,并在 BaseSelect 中将清理内部搜索的 effect 依赖从 mergedOpen 改为 rawOpen;新增测试覆盖 notFoundContent 为 null 时的搜索行为。

Changes

Cohort / File(s) Summary
Hook Signature Update
src/hooks/useOpen.ts
useOpen 的返回由三元组改为四元组,新增首元素 rawOpen(SSR 安全的原始 open 状态),原有的 merged open 移至第二位。
BaseSelect Integration
src/BaseSelect/index.tsx
调整 useOpen 解构以获取 rawOpen,并将清空内部搜索的 effect 依赖从 mergedOpen 改为 rawOpen(避免在未真正打开时触发清空)。
Test Coverage
tests/Select.test.tsx
新增测试:在 notFoundContent === nullshowSearch 开启时,验证输入可持续输入、onSearch 被正确触发以及无匹配时输入不被阻断。

Sequence Diagram(s)

(不需要生成序列图)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • afc163
  • meet-student

Poem

🐰 rawOpen 轻轻跳出头,
mergedOpen 安静守旧筹,
搜索输入不再被吹走,
选项更新也不再忧愁,
测试绿灯欢快跳楼。 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确反映了核心修复内容:当notFoundContent为null时,搜索状态失效的问题。
Linked Issues check ✅ Passed PR的代码变更完整满足三个关联问题的需求:通过引入rawOpen区分搜索框未打开的情况,防止在notFoundContent为null时清空搜索值。
Out of Scope Changes check ✅ Passed 所有代码变更均在解决关联问题范围内,包括useOpen钩子改进、BaseSelect逻辑调整和相关测试。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-empty

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
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 effectively resolves an issue where the Select component's search input was being cleared when notFoundContent was null and no options matched the search. The solution involves introducing a rawOpen state from the useOpen hook to distinguish between a user-initiated close and an automatic one due to empty content. This prevents the search input from being cleared incorrectly, improving the user experience. The changes are well-implemented, and the addition of a new test case ensures the fix is properly verified. I have one minor suggestion to improve code clarity.

Comment on lines 434 to +438
React.useEffect(() => {
if (!mergedOpen && !multiple && mode !== 'combobox') {
if (!rawOpen && !multiple && mode !== 'combobox') {
onInternalSearch('', false, false);
}
}, [mergedOpen]);
}, [rawOpen]);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using rawOpen here is the core of the fix, and it's a good one. To improve maintainability, it would be beneficial to add a comment explaining why rawOpen is used instead of mergedOpen. This would help future developers understand the distinction and the reason for this logic, especially since mergedOpen is used in most other places.

For example:

// Clean up search value when the dropdown is closed.
// We use `rawOpen` here to avoid clearing the search input when the dropdown is
// programmatically closed due to `notFoundContent={null}` and no matching options.
// This allows the user to continue typing their search query.

Clarify why rawOpen is used instead of mergedOpen to prevent
premature clearing of search input.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@zombieJ zombieJ merged commit 6e169e6 into master Feb 5, 2026
12 checks passed
@zombieJ zombieJ deleted the fix-empty branch February 5, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant