fix: 端点 Dialog 表单 submit 事件冒泡导致外层编辑 Dialog 意外关闭#920
Conversation
React 合成事件会沿组件树(而非 DOM 树)冒泡。AddEndpointButton 和 EditEndpointDialog 的 form 虽然通过 Portal 渲染到 body, 但 submit 事件仍然冒泡到宿主 ProviderFormContent 的 form, 触发供应商编辑保存 -> onSuccess -> Dialog 关闭。 在两处 handleSubmit 中添加 e.stopPropagation() 阻止冒泡。
Summary of ChangesHello, 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! 此拉取请求旨在解决一个用户体验问题,即在供应商管理界面中,当用户在内嵌的“添加端点”或“编辑端点”Dialog 中提交表单时,外层的供应商编辑 Dialog 会意外关闭。通过阻止内层表单的 Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
📝 Walkthrough走查概览在提供商端点表组件中,向 AddEndpointButton 和 EditEndpointDialog 的表单提交处理器各添加了一行事件传播阻止代码。 变更
估计代码审查工作量🎯 1 (Trivial) | ⏱️ ~3 分钟 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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.
Code Review Summary
No significant issues identified in this PR.
PR Size: XS
- Lines changed: 2
- Files changed: 1
Analysis
This PR correctly fixes a React synthetic event bubbling issue where nested Dialog forms (via Radix UI Portals) trigger parent form submission. The fix adds e.stopPropagation() to prevent the submit event from propagating up the React component tree.
Root cause correctly identified: Radix UI Portal renders Dialog content to document.body in the DOM, but the element remains a descendant in React's virtual tree, causing synthetic events to bubble through the component hierarchy rather than the DOM tree.
Fix is appropriate:
e.preventDefault()prevents default form submissione.stopPropagation()prevents React synthetic event from bubbling to ancestor form handlers
This is a well-established pattern for nested forms in React applications using Portal-based dialogs.
Review Coverage
- Logic and correctness - Clean
- Security (OWASP Top 10) - Clean
- Error handling - Clean
- Type safety - Clean
- Documentation accuracy - Clean
- Test coverage - Adequate (existing tests cover form submission behavior)
- Code clarity - Good
Automated review by Claude AI
Summary
Fixes nested dialog form submit event bubbling that caused the outer edit dialog to unexpectedly close when submitting the inner endpoint add/edit dialog in the provider management UI.
Problem
In the provider management interface, when editing a provider and clicking "Add Endpoint" to open the nested dialog, filling in the form and clicking "Create" would unexpectedly close the outer edit dialog and return to the provider list. The expected behavior is for only the inner dialog to close, keeping the edit dialog open.
Root Cause: React synthetic events bubble through the component tree (not the DOM tree). The
<form>elements inAddEndpointButtonandEditEndpointDialogare rendered todocument.bodyvia Radix UI Portal, but in React's virtual tree they remain descendants of the outerProviderFormContent's<form>. The inner form'shandleSubmitonly callede.preventDefault()withoute.stopPropagation(), causing thesubmitevent to bubble to the outer<form onSubmit={handleSubmit}>, triggering the provider save flow which calledonSuccess()to close the edit dialog.Solution
Add
e.stopPropagation()to thehandleSubmitfunctions in bothAddEndpointButtonandEditEndpointDialogto prevent submit events from bubbling up.Changes
src/app/[locale]/settings/providers/_components/provider-endpoints-table.tsxe.stopPropagation()to twohandleSubmitfunctions (+2 lines)Testing
Manual Testing
Checklist
devbun run typecheckpassedbun run lintpassedmainNote: This PR modifies
provider-endpoints-table.tsxwhich is also modified in PR #919. Reviewers should be aware of potential merge conflicts.Description enhanced by Claude AI