Skip to content

fix(register): show email warnings while typing (@fehmer) - #8664

Draft
fehmer wants to merge 1 commit into
masterfrom
fix/register-email-warning-sync
Draft

fehmer wants to merge 1 commit into
masterfrom
fix/register-email-warning-sync

Conversation

@fehmer

@fehmer fehmer commented Dec 5, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the register form's email warnings (education / typo / disposable) not appearing in the field indicator while typing test@example.edu (shows the success check instead). Supersedes #8662 (the asyncAlways approach) — same fix, sync validation, plus the two follow-up issues discovered while verifying it.

Introducing PR: #7816 (1cefe7cf4, "refactor: solid settings") rewired the verify-email cross-check from a manual validateField("emailVerify") call to onChangeListenTo: ["email"]. form-core then runs the verify field's sync validator inside the email field's sync pass; while typing, the still-empty verify field errors (verify email not matching email), which sets hasErrored on the email field — and FieldApi.validate aborts the email's async validation on hasErrored && !asyncAlways. emailIsValid never runs, so the warning meta is never set.

Discovered while fixing: the warning state has no reset, and the indicator can't see resets anyway:

  • handleResult only ever set hasWarning/warnings — once shown, a warning stuck on the field permanently after the email stopped matching (latent for a long time: unreachable while the async validation was aborted by refactor: solid settings (@miodec) #7816).
  • hasWarning/warnings are custom meta keys not selected into solid-form's field signal, so a warning-state change alone never re-renders FieldIndicator. The indicator renders the warning from the previous validation pass — a stale check when a warning first appears, a phantom triangle when it's cleared (verified in the browser).

Three-part fix:

 // Register.tsx — email field: run the local warning checks in the sync pass,
 // where they can't be aborted by the linked verify-email mismatch
 <form.Field
   name="email"
   validators={{
-    onChange: fromSchema(UserEmailSchema),
-    onChangeAsyncDebounceMs: 0,
-    onChangeAsync: async (field) =>
-      handleResult(field.fieldApi, await emailIsValid(field.value)),
+    onChange: (field) => {
+      const result = fromSchema(UserEmailSchema)(field);
+      if (result !== undefined) return result;
+      return handleResult(field.fieldApi, emailIsValid(field.value));
+    },
   }}
 // utils.ts — handleResult: sync OR clear the warning meta on every pass
-  if (results === undefined || results.length === 0) return undefined;
-  if (warning) field.setMeta(m => ({ ...m, hasWarning: true, warnings }));
+  const warnings = byType.warning?.map(it => it.message);
+  field.setMeta(m => ({ ...m, hasWarning: warnings !== undefined, warnings: warnings ?? [] }));
 // FieldIndicator.tsx — keep a field-store subscription for the untracked
 // warning meta, so the indicator reacts to warning changes in the same pass
+  const [warningMeta, setWarningMeta] = createSignal(readWarningMeta());
+  onMount(() => {
+    const subscription = props.field.store.subscribe(() => setWarningMeta(readWarningMeta()));
+    onCleanup(subscription.unsubscribe);
+  });

emailIsValid is de-asynced (it contained no await). The FieldIndicator subscription benefits every form that uses warning meta (register email/username, ThirdPartySignUpModal, SimpleModal, ProfileSearchPage).

Evidence

  • Before (introducing PR refactor: solid settings (@miodec) #7816 onward): typing test@example.edu leaves the indicator on fa-check; the field store never shows isValidating: true or hasWarning (async validator aborted).
  • Before (missing reset, once warnings run again): warning sticks after changing to a plain email; and because the indicator only re-renders on tracked meta keys, it lags one pass — stale fa-check when the warning first appears, phantom fa-exclamation-triangle after it's cleared (browser-verified table below).
  • After (browser, fresh page, per-keystroke):
    • type test@example.edu char by char → fa-exclamation-triangle on the final keystroke
    • append x (no warning) → fa-check
    • remove x → fa-exclamation-triangle on the same keystroke
    • plain@example.com → fa-check
  • Tests: FieldIndicator specs updated for the store subscription (fake fields gain a minimal store); utils.spec.ts expectations unchanged and passing. Full suite: 134 files, 2026 tests, all pass. oxlint core + type-aware clean.

Merge Danger

Door: two-way

Blast Radius: register email field behavior + FieldIndicator for all warning-based forms. Warning meta now updates (and clears) in the same validation pass it changes — the visible change for other forms is that their warnings stop being able to stick, which is the intended behavior.

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