Skip to content

fix(studio): migrate email template reset dialog to async AlertDialog - #47705

Merged
joshenlim merged 2 commits into
masterfrom
danny/depr-573-migrate-auth-email-template-reset-dialog-to-async
Jul 8, 2026
Merged

joshenlim merged 2 commits into
masterfrom
danny/depr-573-migrate-auth-email-template-reset-dialog-to-async

Conversation

@dnywh

@dnywh dnywh commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix / refactor. Resolves DEPR-573.

What is the current behavior?

ResetTemplateDialog (added in #45572) confirms the Auth email template reset using the old AlertDialog workaround: an AlertDialogAction with asChild + event.preventDefault() and a manual loading Button, driven by mutate plus inline callbacks. Reset failures are only reported via a toast from the mutation's default onError, so the error disappears from the dialog context.

This predates #45960, which added first-class async handling to AlertDialogAction (promise-returning handlers, controlled loading, and AlertDialogBody for inline feedback). #45960 explicitly flagged ResetTemplateDialog as needing this follow-up migration.

What is the new behavior?

ResetTemplateDialog now uses the async AlertDialogAction pattern:

  • The confirm handler uses mutateAsync and returns the reset promise, so the dialog stays open with a loading state while the mutation is pending and closes only after it succeeds.
  • Reset failures surface inline via a destructive Admonition inside AlertDialogBody, and the mutation's toast-only error path is suppressed (onError: () => {}). The inline error clears when the dialog closes.
  • Cancel is disabled while the reset is in flight.
  • The asChild + preventDefault() workaround and the manual loading Button are removed; loading={isResetting} is retained for parent-controlled loading.

This matches the established usage in DisablePipelinesDialog / JitDbAccessDeleteDialog and the design-system alert-dialog-async-error example.

To test

  • Customise an Auth email template, click Reset template, confirm the dialog shows loading until the reset succeeds and then closes with the editor refreshed to the default subject/body.
  • In DevTools → Network, block */templates/*/reset, click Reset, and confirm the dialog stays open with an inline destructive admonition and no toast.

Summary by CodeRabbit

  • Bug Fixes
    • Improved email template reset error handling by showing reset failures inline in the confirmation dialog (with a destructive alert message).
    • The dialog remains open on reset failure so users can review the error and retry.
    • “Cancel” is disabled while resetting; success behavior and existing success toast behavior remain unchanged.
  • Tests
    • Updated reset mutation mock to use async behavior and added coverage for reset failure UI/error handling (including that error toasts are not triggered).

Migrate ResetTemplateDialog to the async AlertDialogAction pattern so the
reset confirmation returns the mutation promise, keeps the dialog open
while pending, and closes only on success. Failures now surface inline via
a destructive Admonition in AlertDialogBody instead of a toast, and the
asChild + preventDefault workaround is removed.

Resolves DEPR-573.
@dnywh
dnywh requested a review from a team as a code owner July 7, 2026 17:59
@supabase

supabase Bot commented Jul 7, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@vercel

vercel Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment Jul 7, 2026 8:12pm
studio-staging Ready Ready Preview, Comment Jul 7, 2026 8:12pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Jul 7, 2026 8:12pm
design-system Skipped Skipped Jul 7, 2026 8:12pm
docs Skipped Skipped Jul 7, 2026 8:12pm
ui-library Skipped Skipped Jul 7, 2026 8:12pm
zone-www-dot-com Skipped Skipped Jul 7, 2026 8:12pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

ResetTemplateDialog now uses mutateAsync with try/catch to surface reset failures inline, clears error state on close, and updates tests to cover the failure path and the mocked async mutation flow.

Changes

Reset failure surfacing

Layer / File(s) Summary
Error state and mutation handling in ResetTemplateDialog
apps/studio/components/interfaces/Auth/EmailTemplates/ResetTemplateDialog.tsx
Adds AlertDialogBody and Admonition imports, introduces local error state, and replaces the mutate/onSuccess pattern with mutateAsync wrapped in try/catch that sets error on failure and clears it when the dialog closes.
Dialog UI updates for error display
apps/studio/components/interfaces/Auth/EmailTemplates/ResetTemplateDialog.tsx
Conditionally renders a destructive Admonition with the error message, disables Cancel while resetting, and calls resetTemplateToDefault directly from the Reset button.
Test coverage for reset failure
apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.test.tsx
Updates the mocked reset mutation to expose mutateAsync and adds a test verifying that on failure the dialog stays open, an inline error is shown, the Reset button remains, and toast.error is not called.

Estimated code review effort: 2 (Simple) | ~12 minutes

Suggested reviewers: kemaldotearth, seanoliver

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: migrating the email template reset dialog to the async AlertDialog pattern.
Description check ✅ Passed The description covers the change, current behavior, new behavior, and testing; only the CONTRIBUTING confirmation and additional context sections are missing.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch danny/depr-573-migrate-auth-email-template-reset-dialog-to-async

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

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

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

🧹 Nitpick comments (1)
apps/studio/components/interfaces/Auth/EmailTemplates/ResetTemplateDialog.tsx (1)

37-37: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Inline Admonition bypasses the established ErrorMatcher architecture.

Studio's error-handling convention routes caught errors through ErrorMatcher (which reads error.errorType off the typed error class for an O(1) troubleshooting lookup), rather than extracting error.message into local string state. Here, setError(error.message ?? ...) discards the typed error object, and the raw string is rendered via a bespoke Admonition instead of ErrorMatcher.

Consider storing the caught error object (not just its message) and rendering via ErrorMatcher for consistency with the rest of Studio, e.g.:

<ErrorMatcher title="Unable to reset email template" error={error} supportFormParams={{ projectRef }} />

This is advisory — if there's no meaningful troubleshooting content for this failure mode, the current inline message is a reasonable simplification.

As per coding guidelines, "Errors flow: handleError() → throws typed subclass → React Query catches → ErrorMatcher reads errorType → renders troubleshooting," and the rules flag when "PR passes error.message instead of the full error object" to the matcher.

Also applies to: 62-65, 90-98

🤖 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
`@apps/studio/components/interfaces/Auth/EmailTemplates/ResetTemplateDialog.tsx`
at line 37, The ResetTemplateDialog error path is bypassing Studio’s standard
ErrorMatcher flow by storing only error.message in local state and rendering a
custom Admonition. Update the error handling in ResetTemplateDialog to keep the
caught error object intact (instead of converting it to a string) and pass that
error into ErrorMatcher so it can use error.errorType consistently with the
existing troubleshooting architecture. Ensure the render path that currently
uses the local error state is replaced with ErrorMatcher, using the dialog’s
existing title/context and supportFormParams where appropriate.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In
`@apps/studio/components/interfaces/Auth/EmailTemplates/ResetTemplateDialog.tsx`:
- Line 37: The ResetTemplateDialog error path is bypassing Studio’s standard
ErrorMatcher flow by storing only error.message in local state and rendering a
custom Admonition. Update the error handling in ResetTemplateDialog to keep the
caught error object intact (instead of converting it to a string) and pass that
error into ErrorMatcher so it can use error.errorType consistently with the
existing troubleshooting architecture. Ensure the render path that currently
uses the local error state is replaced with ErrorMatcher, using the dialog’s
existing title/context and supportFormParams where appropriate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 773f22e7-90cb-4c01-8fb1-8e2cd7dfe37e

📥 Commits

Reviewing files that changed from the base of the PR and between 586ed82 and 1eae11d.

📒 Files selected for processing (2)
  • apps/studio/components/interfaces/Auth/EmailTemplates/ResetTemplateDialog.tsx
  • apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.test.tsx

@github-actions

github-actions Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  231 passed
flaky  1 flaky
skipped  5 skipped

Details

stats  237 tests across 27 suites
duration  5 minutes, 3 seconds
commit  7bd7fb4

Flaky tests

Features › queue-table-operations.spec.ts › Queue Table Operations › pending changes persist when switching between tables

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

Narrow the caught reset error with an instanceof Error check instead of
typing it as any, to satisfy the no-explicit-any lint ratchet.

Copilot AI 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.

Pull request overview

This PR updates the Studio Auth email template “Reset template” confirmation flow to use the newer async-capable AlertDialogAction API, keeping the dialog open during the reset mutation and surfacing failures inline instead of via a toast-only error path.

Changes:

  • Migrated ResetTemplateDialog to use mutateAsync with async AlertDialogAction handling (loading/close-on-success/stay-open-on-error).
  • Added inline error rendering via AlertDialogBody + destructive Admonition, with error state cleared on dialog close.
  • Updated TemplateEditor tests to mock mutateAsync and added a failure-path assertion (dialog remains open, inline error shown, no toast error).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.test.tsx Updates reset mutation mocking to mutateAsync and adds a failure-path test for inline error behavior.
apps/studio/components/interfaces/Auth/EmailTemplates/ResetTemplateDialog.tsx Refactors the reset confirmation dialog to the async AlertDialogAction pattern and displays reset errors inline.

Comment on lines +60 to +69
try {
await resetAuthTemplate({ projectRef, template: templateType })
} catch (error) {
setError(
error instanceof Error
? error.message
: 'An unknown error occurred while resetting the template'
)
throw error
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we could stick to using mutate - these could be handled in onError handler

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ohhh it must depend on async here for the async loading

@joshenlim joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested on preview!

@joshenlim
joshenlim merged commit fa20667 into master Jul 8, 2026
37 checks passed
@joshenlim
joshenlim deleted the danny/depr-573-migrate-auth-email-template-reset-dialog-to-async branch July 8, 2026 06:43
@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1783493172)

Score Average Improvements Regressions
Knowledge Usage 97.4% (+0pp) 1 🟢 1 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+0pp) - -
Tool Usage 76.5% (+0pp) 1 🟢 1 🔴
Time_to_first_token 3.01tok (+0.03tok) 13 🟢 16 🔴
Llm_calls 2.78 (-0.13) 13 🟢 14 🔴
Tool_calls 3.08 (+0.03) 11 🟢 11 🔴
Errors 5.28 (-0.02) 4 🟢 4 🔴
Llm_errors 0 (+0) - -
Tool_errors 0 (+0) - -
Prompt_tokens 23076.49tok (-2854.59tok) 13 🟢 12 🔴
Prompt_cached_tokens 6897.29tok (-829.79tok) 12 🟢 14 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 652.4tok (+58.52tok) 14 🟢 15 🔴
Completion_reasoning_tokens 105.68tok (+1.48tok) 13 🟢 13 🔴
Total_tokens 23728.9tok (-2796.07tok) 17 🟢 12 🔴
Estimated_cost 0$ (0$) 11 🟢 14 🔴
Duration 16.72s (-0.97s) 18 🟢 11 🔴
Llm_duration 10.55s (-1.29s) 19 🟢 10 🔴

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.

3 participants