Skip to content

fix: the bug in the lock method of the vbenModal component - #6648

Merged
jinmao88 merged 1 commit into
vbenjs:mainfrom
Elm1992:fix/modal-lock-issue
Aug 21, 2025
Merged

jinmao88 merged 1 commit into
vbenjs:mainfrom
Elm1992:fix/modal-lock-issue

Conversation

@Elm1992

@Elm1992 Elm1992 commented Aug 17, 2025 •

Copy link
Copy Markdown
Contributor

Description

vbenModal 组件,设置 lock 方法,然后 close 方法关闭弹窗,快速点击有时候执行了两次确定按钮。

image

简单的 modal close 方法加个定时器快速点击偶尔也能复现
项目里 modal 实际 dom 会多一些,快速点击很容易复现,modal 消失之前及时是有 lock 方法,页面关闭之前也能再点击一次。

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Summary by CodeRabbit

  • Bug Fixes
    • Adjusted modal behavior for more predictable submission handling. Closing a modal no longer clears the submission state, preventing unintended resets mid-flow. When the modal is opened, the submission state is now reset to provide a clean start. This ensures consistent user experience across open/close cycles, reduces confusion around in-progress actions, and aligns modal behavior with expected form interactions.

@changeset-bot

changeset-bot Bot commented Aug 17, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 623e0c1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 17, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adjusted modal state management in modal-api.ts: opening the modal now explicitly resets submitting to false, while closing no longer modifies submitting and only sets isOpen to false. No public API signatures were changed.

Changes

Cohort / File(s) Summary
Modal state handling
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts
Moved submitting reset from close() to open(): close() now only sets isOpen: false; open() sets isOpen: true and submitting: false. No exported/public signature changes.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ModalAPI
  participant ModalState

  Caller->>ModalAPI: open()
  ModalAPI->>ModalState: set { isOpen: true, submitting: false }

  Caller->>ModalAPI: close()
  ModalAPI->>ModalState: set { isOpen: false }
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • anncwb
  • jinmao88
  • vince292007

Poem

I hop to the modal, ears held high,
Open says “reset,” close says “bye.”
Submitting sleeps till next reveal,
A tidy state, a cleaner feel.
Thump-thump—UI dreams align,
Carrots queued, code’s divine. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (2)
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (2)

38-63: Initialize submitting in defaultState to stabilize reactive shape

submitting is read and written elsewhere (lock/open), but it isn’t present in the initial state. Defining it up-front avoids undefined vs false checks and ensures a stable object shape for reactivity and SSR hydration.

Apply this diff to add it:

       confirmLoading: false,
+      submitting: false,
       contentClass: '',

150-152: Optional guard: ignore confirm while locked or not open

This provides a cheap extra safety net against stray events during closing/locked states. Not required for the main fix, but it hardens the API.

Apply this diff:

-  onConfirm() {
-    this.api.onConfirm?.();
-  }
+  onConfirm() {
+    // Ignore redundant confirms while locked or while modal is not open
+    if (this.state?.submitting || !this.state?.isOpen) return;
+    this.api.onConfirm?.();
+  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ff4704d and 623e0c1.

📒 Files selected for processing (1)
  • packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (2)
packages/@core/ui-kit/popup-ui/src/modal/modal-api.ts (2)

164-168: Moving submitting reset to open() fixes the post-close double-click race — LGTM

Clearing submitting only on open prevents the transient re-enable window during close. This directly addresses the reported double-confirm issue from rapid clicks.


102-112: Confirm no internal breakages, but audit external usages of submitting flag
We’ve verified that in modal-api.ts the new close() no longer clears submitting, whereas open() still sets submitting: false. Internally, the only logic tied to submitting on close is the gating on update:open (@update:open="() => (!submitting ? modalApi.close() : undefined)") and the usual escape/interact blockers in modal.vue. No other handlers (including handleClosed) reset submitting.

However, since drawer’s close() still resets submitting and external consumers might rely on modalApi.onClosed or watchers seeing submitting clear when a modal closes, please:

• Audit any downstream code (in applications or other packages) that:
– Calls modalApi.close() and then reads submitting
– Relies on onClosed callbacks to run with submitting === false
– Uses @update:open or other transition hooks expecting submitting to reset on close
• Consider either restoring this.store.setState({ submitting: false }) in modal-api.ts#close() for parity with drawer, or explicitly documenting that submitting now persists through close until the next open()

No direct internal fixes needed, but this is a breaking behavior change for consumers—please verify and update accordingly.

@jinmao88
jinmao88 merged commit 2cc78f9 into vbenjs:main Aug 21, 2025
dtera pushed a commit to dtera/vue-admin that referenced this pull request Sep 5, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants