fix(keys): refresh API key form options - #5512
Conversation
- enable model and group queries only while the API key drawer is open and remove the five-minute stale window so the form uses fresh backend options. - align the API key table group-ratio query key to avoid duplicate caches for the same group endpoint.
WalkthroughTwo React Query configurations in the API keys feature are updated: ChangesAPI Keys React Query Cache Configuration
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/features/keys/components/api-keys-mutate-drawer.tsx`:
- Around line 115-116: The form reset effect on line 150 that depends on
backendHasAuto is re-running when the user-groups query completes after the
drawer opens, causing unwanted form resets in create mode. To fix this, add a
condition to the reset effect to check if the form is dirty (using
form.formState.isDirty) before resetting, so that any user edits are preserved.
Specifically, wrap the reset logic with a guard that prevents resetting when the
form has been modified by the user (isDirty is true).
🪄 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: 62f44946-ab5f-425d-9fd5-91be28b4f064
📒 Files selected for processing (2)
web/default/src/features/keys/components/api-keys-columns.tsxweb/default/src/features/keys/components/api-keys-mutate-drawer.tsx
| enabled: open, | ||
| staleTime: 0, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Read-only verification: confirm reset effect depends on backendHasAuto and is triggered by groups query timing.
rg -n -C3 "enabled:\s*open|backendHasAuto|form\.reset\(" web/default/src/features/keys/components/api-keys-mutate-drawer.tsxRepository: QuantumNous/new-api
Length of output: 1394
Prevent form reset triggered by delayed user-groups query completion.
The enabled: open gate on line 115 delays groupsData load, causing backendHasAuto to transition from false to true after the drawer opens. Since the reset effect on line 150 depends on backendHasAuto, it re-runs when the groups query completes, resetting form values in create mode even if the user has started editing. Gate the reset to the initial open transition only, or add a check like !form.formState.isDirty to avoid resetting if the form has been modified.
🤖 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/keys/components/api-keys-mutate-drawer.tsx` around
lines 115 - 116, The form reset effect on line 150 that depends on
backendHasAuto is re-running when the user-groups query completes after the
drawer opens, causing unwanted form resets in create mode. To fix this, add a
condition to the reset effect to check if the form is dirty (using
form.formState.isDirty) before resetting, so that any user edits are preserved.
Specifically, wrap the reset logic with a guard that prevents resetting when the
form has been modified by the user (isDirty is true).
Upstream changes (50+ commits, v1.0.0-rc.11): - data-table perf: row selection memo, column pinning, badge display - Fixes: channel test dialog (QuantumNous#5517), CC Switch model selector (QuantumNous#5515), API key form options (QuantumNous#5512), cell overflow (QuantumNous#5510), kimi k2.6 temp (QuantumNous#5390), Anthropic-compatible GLM chunked encoding (QuantumNous#5307), streaming image relay (QuantumNous#4608) - Feat: audit auth method tracking (QuantumNous#5462), channel affinity clear toggle (QuantumNous#5306), relay idle timeout config (QuantumNous#5309), 6-decimal pricing precision (QuantumNous#5332) - Classic frontend: Rsbuild support, Semi React 19 adapter - Shared dialog wrapper, JSON code editor, debounce channel search Conflict resolved: web/bun.lock (accepted upstream, will regenerate) Co-Authored-By: Claude <noreply@anthropic.com>
Merge upstream v1.0.0-rc.11 (50+ commits): - data-table perf: row selection memo, column pinning, badge display - Fixes: channel test dialog (QuantumNous#5517), CC Switch (QuantumNous#5515), API key (QuantumNous#5512), kimi k2.6 temp (QuantumNous#5390), GLM chunked encoding (QuantumNous#5307), streaming image (QuantumNous#4608) - Feat: audit auth tracking (QuantumNous#5462), channel affinity toggle (QuantumNous#5306), relay idle timeout (QuantumNous#5309), 6-decimal pricing (QuantumNous#5332) - Shared dialog wrapper, JSON code editor, classic Rsbuild support SEO optimization: - robots.txt: 10 AI crawler blocks + 22 path disallows + crawl-delay - sitemap.xml: 7 public URLs with 6-language hreflang annotations - index.html: hreflang tags, og:locale:alternate, og:image, canonical, 5 structured data types (Organization, SoftwareApplication, FAQPage, WebSite, SearchAction), expanded keywords (gateway, agent router, aggregation, orchestration) - i18n/config.ts: sync <html lang> with active language for SEO Co-Authored-By: Claude <noreply@anthropic.com>
- enable model and group queries only while the API key drawer is open and remove the five-minute stale window so the form uses fresh backend options. - align the API key table group-ratio query key to avoid duplicate caches for the same group endpoint.
- enable model and group queries only while the API key drawer is open and remove the five-minute stale window so the form uses fresh backend options. - align the API key table group-ratio query key to avoid duplicate caches for the same group endpoint.
- enable model and group queries only while the API key drawer is open and remove the five-minute stale window so the form uses fresh backend options. - align the API key table group-ratio query key to avoid duplicate caches for the same group endpoint.
- enable model and group queries only while the API key drawer is open and remove the five-minute stale window so the form uses fresh backend options. - align the API key table group-ratio query key to avoid duplicate caches for the same group endpoint.
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
问题描述
修复方式
user-models和user-groups查询改为 drawer 打开时启用,并设置staleTime: 0。user-groupsquery key,并取消 5 分钟 stale 缓存。测试说明
bun run typecheck。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit
Bug Fixes