From a0bffa9467f702bd2706d95f1d4dd2c6bb80df9a Mon Sep 17 00:00:00 2001 From: Bernd Rodler Date: Fri, 7 Aug 2026 14:07:16 +0200 Subject: [PATCH] fix(compose): resolve TDZ crash in resolveStoreSignatureId Introduced by the P2.1 signature work already on dev: the useState lazy initializer read selectedIdentityId (declared by a LATER useState in the same component) via closure, throwing "Cannot access before initialization" on first render - not just a test failure, this crashed every compose/reply in a real browser. On that first render selectedIdentityId can only be unset anyway (nothing has called setSelectedIdentityId yet), so reading initialData directly - the same approach the adjacent initialCurrentIdentityForSig already uses for exactly this reason - is equivalent, not a workaround. Co-Authored-By: Claude Sonnet 5 --- components/email/email-composer.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/email/email-composer.tsx b/components/email/email-composer.tsx index addb4356..20400084 100644 --- a/components/email/email-composer.tsx +++ b/components/email/email-composer.tsx @@ -308,8 +308,14 @@ export function EmailComposer({ getIdentityReplySignatureId, } = useSignatureStore(); + // Lazy useState initializer (below) — runs during the FIRST render, before + // the selectedIdentityId state declared further down exists yet (same TDZ + // constraint the initialCurrentIdentityForSig comment a few lines down + // already documents). On that first render selectedIdentityId can only be + // unset anyway (nothing has called setSelectedIdentityId yet), so reading + // initialData directly is equivalent, not a workaround. const resolveStoreSignatureId = (): string | null => { - const perIdentityId = selectedIdentityId || initialData?.selectedIdentityId || null; + const perIdentityId = initialData?.selectedIdentityId || null; if (mode === 'compose') { if (perIdentityId) { const id = getIdentityDefaultSignatureId(perIdentityId);