Fix two things live testing on 0.15.5 turned up

**About said "not detected".** Generation was only worked out from the reply to
a registry method, which we never send to a server that does not advertise
urn:stalwart:jmap — every 0.16 build does, and nothing older knows the
capability at all, so its absence is already the answer. Say so, instead of
shrugging. A session with no capabilities at all stays unknown, which is a
different thing from old.

**The caret jumped out of the OTP field after one digit.** Dialog's autofocus
effect listed onClose in its dependencies, and every caller passes an inline
arrow, so each keystroke in a dialog holding state tore the effect down, set it
up again, and refocused the first field — which in the disable-2FA dialog is
the password. Keep the handler in a ref so the effect depends only on `open`.
This was a bug in the shared dialog rather than in one screen; every dialog
with more than one field had it.

The test for it fails against the old dependency array, not just passes
against the new one.
This commit is contained in:
2026-08-24 09:04:16 -07:00
parent c8fe822586
commit 0fdcbbc778
4 changed files with 119 additions and 4 deletions
+12 -2
View File
@@ -16,13 +16,23 @@ interface DialogProps {
export function Dialog({ open, onClose, title, children, footer, size = "md", closeOnBackdrop = true, className }: DialogProps) {
const ref = useRef<HTMLDivElement>(null);
/*
* Callers almost always pass an inline arrow for onClose, so its identity
* changes on every render of the parent. Depending on it here would tear the
* effect down and set it up again on every keystroke in a dialog that holds
* state, and the autofocus below would drag the caret back to the first
* field mid-typing. Keep the latest handler in a ref instead, so the effect
* depends only on `open`.
*/
const onCloseRef = useRef(onClose);
onCloseRef.current = onClose;
useEffect(() => {
if (!open) return;
const prev = document.activeElement as HTMLElement | null;
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") {
e.stopPropagation();
onClose();
onCloseRef.current();
}
if (e.key === "Tab" && ref.current) {
const focusables = ref.current.querySelectorAll<HTMLElement>('button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[contenteditable="true"]');
@@ -48,7 +58,7 @@ export function Dialog({ open, onClose, title, children, footer, size = "md", cl
document.removeEventListener("keydown", onKey, true);
prev?.focus?.();
};
}, [open, onClose]);
}, [open]);
if (!open) return null;
return createPortal(
<div