Skip to content

perf(web): add debounce channel search and skip during IME composition - #5393

Merged
seefs001 merged 2 commits into
QuantumNous:mainfrom
QAbot-zh:channel-search-ime-debounce
Jun 10, 2026
Merged

perf(web): add debounce channel search and skip during IME composition#5393
seefs001 merged 2 commits into
QuantumNous:mainfrom
QAbot-zh:channel-search-ime-debounce

Conversation

@QAbot-zh

@QAbot-zh QAbot-zh commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

新版默认前端,渠道搜索未添加防抖,以及中文输入拼音、未选中候选字时也会进入搜索,导致触发大量非预期搜索,给数据库造成压力,当前添加了防抖和中文输入状态的处理

Image_2026-06-09_15-58-17_fa15j4bv 1tu

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

(请在此粘贴截图、关键日志或测试报告,以证明变更生效)

(有在本地运行测试,中文输入过程不会触发多余搜索)
Image_2026-06-09_16-02-46_tzvdhf5h aof

Summary by CodeRabbit

  • Improvements
    • Added configurable search debouncing to reduce unnecessary updates and improve responsiveness.
    • Improved handling for multilingual/IME typing so compositions commit correctly when finished.
    • Inputs now avoid redundant filter updates and better synchronize with URL-driven filters.
    • Reset now reliably clears pending input and composition state for consistent behavior.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f09cbf36-e5eb-4ada-892a-7be915eb9b8d

📥 Commits

Reviewing files that changed from the base of the PR and between 3b5def0 and bc7b146.

📒 Files selected for processing (2)
  • web/default/src/components/data-table/toolbar.tsx
  • web/default/src/features/channels/components/channels-table.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/default/src/components/data-table/toolbar.tsx
  • web/default/src/features/channels/components/channels-table.tsx

Walkthrough

This PR introduces debounced, IME-composition-aware search input handling. The generic data-table toolbar gains a searchDebounceMs prop and a state machine that separates immediate display (searchValue) from debounced commits (pendingSearchValue), pausing updates during text composition. The channels table component applies this pattern to its model filter input with dedicated composition handlers.

Changes

Debounced composition-aware search

Layer / File(s) Summary
Data-table toolbar debounced search implementation
web/default/src/components/data-table/toolbar.tsx
Toolbar adds searchDebounceMs prop and introduces composition-tracking refs, dual search state (current/pending), and debounce integration via useDebounce hook. Effects synchronize external filter changes while respecting composition state; change/composition handlers manage state transitions; reset clears all search-related tracking and state.
Channels table model filter composition handling
web/default/src/features/channels/components/channels-table.tsx
Channels table applies composition-aware pattern to model filter: imports event types, adds composition ref and dual state (input/pending), skips input rewrite from URL during composition, and wires input with onChange/onCompositionStart/onCompositionEnd handlers and updated reset logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble keys and pause mid-phrase, 🐰
Composition held in gentle gaze,
Debounce waits for words to rest,
Then commits the search that's best,
Two inputs hop in tidy sync. ✨

🚥 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 The title clearly and specifically describes the main changes: adding debounce to channel search and handling IME composition state, which directly aligns with the changeset's primary objectives of improving search performance and preventing unintended searches during Chinese input composition.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web/default/src/features/channels/components/channels-table.tsx (1)

141-158: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reset and URL sync can resurrect the previous model filter.

This debounced writeback has the same stale-value replay problem as the shared toolbar: after onReset clears modelFilterPendingValue, debouncedModelFilter still holds the old term until the timer catches up, so the effect on Lines 149-158 writes the old value straight back into columnFilters. In practice, Reset/back-forward can restore the previous model filter and fire an extra search. Skip commits when the debounced value no longer matches the current pending value.

Suggested fix
  useEffect(() => {
-    if (debouncedModelFilter !== modelFilterFromUrl) {
+    if (
+      debouncedModelFilter === modelFilterPendingValue &&
+      debouncedModelFilter !== modelFilterFromUrl
+    ) {
       onColumnFiltersChange((prev) => {
         const filtered = prev.filter((f) => f.id !== 'model')
         return debouncedModelFilter
           ? [...filtered, { id: 'model', value: debouncedModelFilter }]
           : filtered
       })
     }
-  }, [debouncedModelFilter, modelFilterFromUrl, onColumnFiltersChange])
+  }, [
+    debouncedModelFilter,
+    modelFilterFromUrl,
+    modelFilterPendingValue,
+    onColumnFiltersChange,
+  ])

Also applies to: 424-428

🤖 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 `@web/default/src/features/channels/components/channels-table.tsx` around lines
141 - 158, The debounced writeback effect can reapply a stale model filter after
a reset because debouncedModelFilter may lag behind modelFilterPendingValue;
update the effect (the second useEffect that currently checks
debouncedModelFilter !== modelFilterFromUrl) to additionally verify that
debouncedModelFilter === modelFilterPendingValue before calling
onColumnFiltersChange so you only commit debounced values that still match the
current pending value (use the existing modelFilterPendingValue variable),
keeping the rest of the logic that filters/updates the 'model' column filter
intact.
🤖 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 `@web/default/src/components/data-table/toolbar.tsx`:
- Around line 171-203: The effect that calls
commitSearchValue(debouncedSearchValue) can apply a stale debounced term; modify
that effect to guard against outdated debounce results by verifying the
debouncedSearchValue matches the current pendingSearchValue (and still not
composing) before calling commitSearchValue. In other words, inside the
React.useEffect that depends on commitSearchValue, debouncedSearchValue and
searchDebounceMs, return early if isSearchComposingRef.current is true or if
debouncedSearchValue !== pendingSearchValue (and optionally if
debouncedSearchValue === lastCommittedSearchValueRef.current) so
commitSearchValue only runs for the latest pending value.

---

Outside diff comments:
In `@web/default/src/features/channels/components/channels-table.tsx`:
- Around line 141-158: The debounced writeback effect can reapply a stale model
filter after a reset because debouncedModelFilter may lag behind
modelFilterPendingValue; update the effect (the second useEffect that currently
checks debouncedModelFilter !== modelFilterFromUrl) to additionally verify that
debouncedModelFilter === modelFilterPendingValue before calling
onColumnFiltersChange so you only commit debounced values that still match the
current pending value (use the existing modelFilterPendingValue variable),
keeping the rest of the logic that filters/updates the 'model' column filter
intact.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4fdcf3ce-d8a3-4dca-9779-f606b8b22546

📥 Commits

Reviewing files that changed from the base of the PR and between d2576dd and 3b5def0.

📒 Files selected for processing (2)
  • web/default/src/components/data-table/toolbar.tsx
  • web/default/src/features/channels/components/channels-table.tsx

Comment thread web/default/src/components/data-table/toolbar.tsx Outdated
@seefs001
seefs001 merged commit 30d3a3a into QuantumNous:main Jun 10, 2026
1 check passed
zhaodechao2008 pushed a commit to zhaodechao2008/new-api that referenced this pull request Jul 27, 2026
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