Skip to content

fix: replace window.confirm with custom modal in embedded Plugin Page#210

Closed
YumemiDream wants to merge 2 commits into
NickCharlie:mainfrom
YumemiDream:fix/embedded-page-confirm-modal
Closed

fix: replace window.confirm with custom modal in embedded Plugin Page#210
YumemiDream wants to merge 2 commits into
NickCharlie:mainfrom
YumemiDream:fix/embedded-page-confirm-modal

Conversation

@YumemiDream

@YumemiDream YumemiDream commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Description:

The embedded Plugin Page runs inside a sandboxed iframe without
'allow-modals', so window.confirm() calls are silently blocked by the
browser. This caused all batch operations (approve/reject/delete) on
the reviews, jargon, and expression-learning pages to appear unresponsive.

Replace all window.confirm() calls with a custom showConfirm() function
that renders a confirmation dialog using the existing element,
which works within sandbox restrictions.

Summary

内嵌 Plugin Page 运行在 <iframe sandbox="..."> 中,没有 allow-modals 权限,导致 window.confirm()
被浏览器静默拦截(返回 false)。所有使用 window.confirm()
的批量操作(审查队列、黑话学习、表达方式学习的批量批准/拒绝/删除)点击后直接 return,表现为"点击没反应"。

用已有的 <dialog> 元素实现 showConfirm() 替代原生 confirm(),在 sandbox 环境下正常工作。

Changes

  • 新增 showConfirm() 函数,基于 <dialog> 元素实现自定义确认弹窗
  • 替换 handleBatchReviewAction 中的 window.confirm(审查队列批量操作)
  • 替换 handleJargonBatchAction 中的 window.confirm(黑话学习批量操作)
  • 替换 handleStyleBatchAction 中的 window.confirm(表达方式学习批量操作)

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Refactoring (no functional changes)
  • Documentation update
  • Other:

Checklist

  • Code follows the project's coding style
  • Self-reviewed the code changes
  • No new warnings or errors introduced
  • Tested in sandboxed iframe environment

Summary by Sourcery

Replace blocked native confirmation dialogs in the embedded dashboard with a custom modal-based confirmation flow for batch actions.

Bug Fixes:

  • Ensure batch approve/reject/delete actions in reviews, jargon, and expression-learning pages work inside sandboxed iframes by avoiding window.confirm().

Enhancements:

  • Introduce a reusable showConfirm() helper that renders confirmation dialogs using the existing dialog element, with localized titles and button labels as needed.

The embedded Plugin Page runs inside a sandboxed iframe without
'allow-modals', so window.confirm() calls are silently blocked by the
browser. This caused all batch operations (approve/reject/delete) on
the reviews, jargon, and expression-learning pages to appear unresponsive.

Replace all window.confirm() calls with a custom showConfirm() function
that renders a confirmation dialog using the existing <dialog> element,
which works within sandbox restrictions.
@sourcery-ai

sourcery-ai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Replaces blocked window.confirm() calls in the sandboxed embedded Plugin Page with a custom Promise-based confirmation modal built on the existing element, ensuring batch review operations prompt correctly under iframe sandbox restrictions.

Sequence diagram for batch action confirmation with showConfirm

sequenceDiagram
  actor User
  participant Page as PluginPage
  participant Handler as handleBatchReviewAction
  participant Confirm as showConfirm
  participant Modal as detail-modal
  participant API as apiPost

  User->>Page: click batch action button
  Page->>Handler: handleBatchReviewAction(action, kind)
  Handler->>Confirm: showConfirm(title, message, confirmText)
  Confirm->>Modal: setText(modal-title, title)
  Confirm->>Modal: setHtml(modal-body, message+buttons)
  alt modal supports showModal
    Confirm->>Modal: modal.showModal()
  else fallback open attribute
    Confirm->>Modal: modal.setAttribute(open, "")
  end
  User-->>Modal: click confirm-ok
  Modal->>Confirm: modal.close()
  Confirm-->>Handler: Promise resolved true
  Handler->>API: apiPost(...)
  API-->>Handler: result
  Handler-->>User: batch operation completes
Loading

File-Level Changes

Change Details Files
Introduce a reusable dialog-based confirmation helper and use it for all batch actions instead of window.confirm, which is blocked in the sandboxed iframe.
  • Add an async showConfirm(title, message, confirmText) helper that renders a confirmation UI into the existing detail-modal dialog, wiring OK/Cancel/close/cancel events and falling back to window.confirm if the dialog is unavailable or showModal() fails.
  • Ensure the dialog is opened/closed in a sandbox-safe way using showModal() when available or the open attribute as a fallback, and always resolve the confirmation Promise with a boolean.
  • Update handleBatchReviewAction to await showConfirm with a translated batch operation title, interpolated confirmation message, and action label instead of using window.confirm.
  • Update handleJargonBatchAction and handleStyleBatchAction to await showConfirm with their respective i18n keys and action labels for jargon and style batch operations.
pages/dashboard/app.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've left some high level feedback:

  • In showConfirm, each invocation adds a new cancel listener to the shared detail-modal dialog that is only cleaned up if cancel actually fires, so over time multiple unused listeners can accumulate; consider using a single persistent handler or explicitly removing the listener on any path that closes the dialog.
  • The fallback to window.confirm(message) when detail-modal is missing will still silently fail (return false) in the sandboxed iframe environment; if this path is expected to occur there, you may want a different fallback behavior (e.g., always resolving true or showing an inline warning) instead of inheriting the original bug.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `showConfirm`, each invocation adds a new `cancel` listener to the shared `detail-modal` dialog that is only cleaned up if `cancel` actually fires, so over time multiple unused listeners can accumulate; consider using a single persistent handler or explicitly removing the listener on any path that closes the dialog.
- The fallback to `window.confirm(message)` when `detail-modal` is missing will still silently fail (return `false`) in the sandboxed iframe environment; if this path is expected to occur there, you may want a different fallback behavior (e.g., always resolving `true` or showing an inline warning) instead of inheriting the original bug.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

…nferred

When the v2 learning system encounters a jargon term that already exists
and is_complete=True (manually edited or fully inferred), skip the save
to prevent overwriting the user's edits.

Also preserve the existing count when updating an existing record,
instead of resetting it to 1.

Fixes: manually edited jargon meanings get overwritten by re-learning.
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.

1 participant