Skip to content

fix: Key 清除到期时间序列化更稳#534

Merged
ding113 merged 1 commit intodevfrom
fix/key-expire-clear-empty-string
Jan 4, 2026
Merged

fix: Key 清除到期时间序列化更稳#534
ding113 merged 1 commit intodevfrom
fix/key-expire-clear-empty-string

Conversation

@ding113
Copy link
Owner

@ding113 ding113 commented Jan 4, 2026

Summary

Improves the robustness of clearing Key expiration dates by using empty string "" instead of undefined for the clear semantic on the frontend.

改进清除密钥到期时间的稳定性,前端使用空字符串 "" 代替 undefined 来传递"清除"语义。

Problem

After PR #533 fixed the backend to properly handle expiration date clearing, a potential edge case remained: when clearing a Key's expiration date, the frontend used undefined to represent "clear". However, undefined fields may be dropped during Next.js Server Action serialization across the client/server boundary, causing the backend to potentially not recognize the clear intent.

Follow-up to:

Solution

Changed the frontend to use empty string "" instead of undefined when clearing expiration dates:

  1. edit-key-form.tsx: Changed data.expiresAt || undefined to data.expiresAt ?? ""
  2. unified-edit-dialog.tsx: Same change for both addKey and editKey calls

The KeyFormSchema already handles empty string → undefined conversion via preprocess, so this change ensures the field is always present in the serialized payload while maintaining the same backend behavior.

Changes

Core Changes

  • src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx (+2/-1): Use empty string for clear semantic
  • src/app/[locale]/dashboard/_components/user/unified-edit-dialog.tsx (+4/-2): Same change for add/edit key operations

Test Updates

  • tests/unit/actions/keys-edit-key-expires-at-clear.test.ts (+15/-0): Added test case for expiresAt="" clear semantic
  • tests/unit/dashboard/edit-key-form-expiry-clear-ui.test.tsx (+1/-1): Updated comment to reflect new behavior

Testing

Automated Tests

  • Unit test added for expiresAt="" case
  • Existing test comments updated

Local Verification

All checks passed:

bun run lint && bun run typecheck && bun run test && bun run test:coverage && bun run build

Checklist

  • Code follows project conventions
  • Self-review completed
  • Tests pass locally
  • Builds successfully

Description enhanced by Claude AI

@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

该PR调整了密钥过期时间清除时的值传递方式,从在客户端发送 undefined 改为发送空字符串(""),通过 nullish coalescing 操作符(??)替代逻辑或操作符(||)实现,以便服务器端能正确识别显式清除操作。

Changes

Cohort / File(s) 变更摘要
客户端过期时间处理
src/app/[locale]/dashboard/_components/user/forms/edit-key-form.tsx, src/app/[locale]/dashboard/_components/user/unified-edit-dialog.tsx
修改 expiresAt 赋值逻辑,从 data.expiresAt || undefined 改为 data.expiresAt ?? "",确保清除过期时间时发送空字符串而非 undefined,以改善服务器端序列化行为
单元测试补充与注释更新
tests/unit/actions/keys-edit-key-expires-at-clear.test.ts, tests/unit/dashboard/edit-key-form-expiry-clear-ui.test.tsx
新增测试用例验证 editKey 接收空字符串时能正确清除 expires_at;更新测试注释以反映清除操作使用空字符串的约定

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 标题清晰地总结了主要变更:将 Key 的过期时间清除逻辑从 undefined 改为空字符串,以改善序列化的稳定性。
Description check ✅ Passed The pull request description clearly explains the problem (undefined fields being dropped during serialization), the solution (using empty string instead), and provides specific file changes with rationale.
✨ 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/key-expire-clear-empty-string

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ding113, 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!

此拉取请求旨在增强 Key 到期时间清除功能的稳定性。通过将前端清除操作从传递 undefined 更改为传递空字符串 "",解决了跨 Next Server Action 序列化边界时 expiresAt 字段可能被意外丢弃的问题,从而确保后端能够可靠地识别并处理到期时间的显式清除,最终将其存储为 null

Highlights

  • 修复序列化问题: 解决了 expiresAt 字段在前端清除时使用 undefined 表达,但在 Next Server Action 序列化边界可能被丢弃,导致后端无法识别为“显式清除”的问题。
  • 采用空字符串作为哑值: 前端清除 expiresAt 时,现在改用空字符串 "" 作为哑值传递,确保字段在序列化后仍然存在。
  • 后端稳定写入 null: KeyFormSchema 会将 "" 转换回 undefined,但由于字段已序列化,后端可以稳定地将其写入 null
  • 新增单元测试: 补充了新的单元测试,覆盖了 expiresAt="" 清除语义,确保其行为符合预期。
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.

@github-actions github-actions bot added bug Something isn't working area:UI size/XS Extra Small PR (< 50 lines) labels Jan 4, 2026
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

本次 PR 旨在修复清除 Key 到期时间在序列化过程中可能失败的问题。通过将前端清除到期时间的值从 undefined 改为 "",确保了该字段在 Next.js Server Action 序列化边界中不会被丢弃,从而使后端能够稳定地识别并执行清除操作(写入 null)。相关改动已在 edit-key-form.tsxunified-edit-dialog.tsx 中统一应用,逻辑清晰。同时,新增的单元测试 tests/unit/actions/keys-edit-key-expires-at-clear.test.ts 很好地覆盖了 expiresAt=\"\" 的场景,保证了修复的正确性和未来的稳定性。整体来看,这是一个高质量的修复,代码改动精准,考虑周全,并有测试保障。

@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2026

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

@ding113 ding113 merged commit d302935 into dev Jan 4, 2026
16 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Jan 4, 2026
Copy link
Contributor

@github-actions github-actions 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 Summary

No significant issues identified in this PR.

PR Size: XS

  • Lines changed: 26
  • Files changed: 4

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Codex AI

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Reviewed PR #534 (fix: Key 清除到期时间序列化更稳).

  • PR size classified as XS (22 additions + 4 deletions = 26 lines, 4 files) and applied label size/XS.
  • No diff-line issues met the reporting threshold (≥80 confidence), so no inline comments were posted.
  • Submitted the required PR review summary via gh pr review --comment.

This was referenced Jan 6, 2026
@ding113 ding113 deleted the fix/key-expire-clear-empty-string branch January 27, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI bug Something isn't working size/XS Extra Small PR (< 50 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant