Repository navigation
Description
Saving the New User Email Template on /admin/mail throws away any unsaved edits in the Mail Server Configuration form above it. Both sections save through the same save helper in MailSettings. After any successful PATCH, that helper resets the server form from the response with setValues(initialValues(next.config)), including when the PATCH only carried newUserEmailTemplate. Host, port, username, a newly typed password and sender fields all go back to their stored values while a success toast is shown. On first-time setup (config is null) it is worse: initialValues(null) sets enabled: false, so the whole server form disappears and everything the admin typed into it is gone.
Where
apps/web/src/components/MailSettings/MailSettings.tsx:126-132:
const save = async (data: Parameters<typeof updateMutation.mutateAsync>[0]) => {
try {
const next = await updateMutation.mutateAsync(data);
// Re-seed from what the server actually stored, ...
setValues(initialValues(next.config));
addNotification({ type: 'success' });MailSettings.tsx:204-208: the template section saves through the same helper:
<NewUserTemplateSection
isSaving={updateMutation.isPending}
template={newUserEmailTemplate}
onSave={(next) => void save({ newUserEmailTemplate: next })}
/>Reproduce
- Sign in as an admin on an instance with a saved mail configuration and open
/admin/mail. - Change Host to
smtp2.example.organd do not click the server form's Save. - Edit the New User Email Template and click its Save.
Actual: the success toast shows, and Host is back to the stored value. The edit is gone without warning.
Expected: saving the template leaves the server form exactly as the admin left it.
Variant: on an instance with no mail configuration, tick "Enable email sending", fill in the server fields, then save the template. The server form collapses and every field typed into it is lost.
Tests
apps/web/src/components/MailSettings/__tests__/MailSettings.test.tsx:
it('should keep unsaved server edits when the template is saved, so one section cannot discard the other')it('should keep the server form open when the template is saved before any configuration exists')
testing/src/specs/mail.spec.ts: test('should keep an unsaved host edit after saving the welcome template').
Suggested fix
Re-seed values only when the payload included config. Either pass a flag to save, or move the setValues call into handleSaveConfig and handleToggleEnabled, so a template-only save never touches the server form state.
Activity
joshunrau commentedon Oct 26, 2026
Still reproduces on
main(d86740e). The cited lines have not moved.The variant is wider than first-time setup
initialValuestakesenabledfrom the stored config (MailSettings.tsx:23), and the template section only renders undervalues.enabled(MailSettings.tsx:191). Ticking "Enable email sending" never saves (MailSettings.tsx:160). So the collapse happens on any instance where mail is configured but switched off, not only whenconfigisnull. There, every template save hides the card that was just saved, even with no server edits. The e2email settingsblock runs in this state: itsbeforeAllcallsapi.setMailEnabled(false)(mail.spec.ts:17), which storesE2E_MAIL_CONFIGwithenabled: false.Fix
Decide from the payload.
data.configalready says whether the server form was saved, so a separate flag would be a second source for the same fact:This keeps the re-seed for
handleSaveConfigand for the disable inhandleToggleEnabled, the only other callers ofsave. The other direction is already safe:NewUserTemplateSectionseeds its state once (NewUserTemplateSection.tsx:28-31) and never re-reads thetemplateprop, so a server save cannot discard template edits.Tests
MailSettings.test.tsx: thebeforeEachmock resolvesconfig: storedConfig, which is enabled, so a collapse test that uses it passes onmainfor the wrong reason. Override the PATCH to resolve what the server would actually return:config: nullfor the first-time case, and{ ...storedConfig, enabled: false }for a third test that renders that disabled config and ticks Enable first. The host-edit test works with the default mock.mail.spec.ts: onmainthe template Save is disabled out of the box, because the built-in default has no Spanish (New user email template cannot be saved because the built-in default has no Spanish text #1665). Land this after New user email template cannot be saved because the built-in default has no Spanish text #1665 is fixed. fix(web): scope email template languages to active languages #1810 adds Spanish toDEFAULT_NEW_USER_EMAIL_TEMPLATE. Put the test in themail settingsblock and callapi.setMailEnabled(false)inside it, so it does not depend on running before the save test atmail.spec.ts:90, which storesenabled: true. Enable mail, change Host, and save the template unchanged. After the Success toast, assert thatserverCardis visible andhoststill holds the unsaved value.Separate bug in the same helper
handleToggleEnabledsetsenabledto false locally before the PATCH (MailSettings.tsx:157), and thecatchinsavenever puts it back. When a disable fails, the checkbox stays unticked and the form stays hidden while mail is still on server-side. No issue tracks this. It needs its own issue rather than a fix in this one.Triage note written with Claude Code. Code references point at
main@d86740e.