Skip to content

fix: allow clearing optional SMTP and email template sender fields#3051

Open
HarshMN2345 wants to merge 3 commits into
mainfrom
fix-smtp-email-template-clear-fields
Open

fix: allow clearing optional SMTP and email template sender fields#3051
HarshMN2345 wants to merge 3 commits into
mainfrom
fix-smtp-email-template-clear-fields

Conversation

@HarshMN2345
Copy link
Copy Markdown
Member

@HarshMN2345 HarshMN2345 commented May 19, 2026

Optional fields (senderEmail, replyToEmail, senderName, replyToName, username, password) could not be cleared once set. The frontend used || undefined which silently dropped empty strings, so the backend never received "" and the old value persisted on reload.

smtp/+page.svelte:

  • Use ?? undefined instead of || undefined so empty strings are sent
  • Fix isButtonDisabled deepEqual comparison: normalize types on both sides (?? '' for strings, ?? null for port, normalizeSecure() for secure) to avoid false positives from null/undefined mismatches
  • Derive project from data.project so it stays reactive after invalidate() — fixes button not disabling after save without reload
  • Remove second $effect that cleared fields on disable, which fought the first effect and kept the button permanently enabled

emailTemplate.svelte:

  • Use ?? undefined instead of || undefined for sender/reply fields
  • Add disabled={!isSmtpEnabled} to replyToEmail and replyToName, matching the existing behaviour of senderName and senderEmail

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

Optional fields (senderEmail, replyToEmail, senderName, replyToName,
username, password) could not be cleared once set. The frontend used
|| undefined which silently dropped empty strings, so the backend
never received "" and the old value persisted on reload.

smtp/+page.svelte:
- Use ?? undefined instead of || undefined so empty strings are sent
- Fix isButtonDisabled deepEqual comparison: normalize types on both
  sides (?? '' for strings, ?? null for port, normalizeSecure() for
  secure) to avoid false positives from null/undefined mismatches
- Derive project from data.project so it stays reactive after
  invalidate() — fixes button not disabling after save without reload
- Remove second $effect that cleared fields on disable, which fought
  the first effect and kept the button permanently enabled

emailTemplate.svelte:
- Use ?? undefined instead of || undefined for sender/reply fields
- Add disabled={!isSmtpEnabled} to replyToEmail and replyToName,
  matching the existing behaviour of senderName and senderEmail
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Greptile Summary

This PR fixes two related bugs: optional SMTP and email-template fields (senderEmail, replyToEmail, senderName, replyToName, username, password) could not be cleared once set because || undefined coerced empty strings to undefined, so the backend never received \"\" and the old value persisted on reload.

  • smtp/+page.svelte: Replaces || undefined with ?? undefined across all optional SMTP fields, switches to $derived(data.project) so the form button correctly disables after a save without a full page reload, normalizes both sides of the deepEqual comparison to avoid null/string false positives, and removes a second $effect that was competing with the first and keeping the Save button permanently enabled.
  • emailTemplate.svelte: Applies the same ?? undefined fix to all six template fields, adds disabled={!isSmtpEnabled} to the reply-to inputs for consistency with the sender fields, and introduces a new "Reset to default" button backed by sdk.forConsole.console.getEmailTemplate to restore system defaults.

Confidence Score: 5/5

Safe to merge — the core logic changes are correct and well-scoped fixes for the described clearing and button-state bugs.

All changes are targeted bug fixes: the ?? undefined substitution correctly allows empty strings to reach the backend, $derived(data.project) properly re-syncs reactivity after invalidation, and the deepEqual normalization eliminates spurious null/string mismatches. The only concern is a recoverable UX edge case in the new resetToDefault path where a failed save leaves the form showing unsaved default values without explicit guidance to retry.

The new resetToDefault function in emailTemplate.svelte warrants a second look for the error-handling gap between saveEmailTemplate and resetToDefault.

Important Files Changed

Filename Overview
src/routes/(console)/project-[region]-[project]/settings/smtp/+page.svelte Three targeted fixes: $derived(data.project) for reactivity after save, ?? undefined to allow sending empty strings that clear optional fields, and a normalized deepEqual comparison that prevents false positives from null/string mismatches — plus removal of the second $effect that was permanently enabling the Save button.
src/routes/(console)/project-[region]-[project]/auth/templates/emailTemplate.svelte Applies ?? undefined to all six template fields (including subject/message), adds disabled={!isSmtpEnabled} to replyToEmail/replyToName for UI consistency, and introduces a new "Reset to default" button with its own async flow; the resetToDefault function has a subtle error-handling gap described in the review comment.
package.json Bumps the pinned @appwrite.io/console SDK commit hash from 7789ae4 to 0387505; routine dependency update.
bun.lock Lockfile updated in sync with the package.json SDK commit bump; no other changes.

Reviews (3): Last reviewed commit: "feat: add reset to default button on ema..." | Re-trigger Greptile

HarshMN2345 and others added 2 commits May 19, 2026 16:35
…/emailTemplate.svelte

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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