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 <noreply@anthropic.com>
This commit is contained in:
Bernd Rodler
2026-08-07 14:07:16 +02:00
co-authored by Claude Sonnet 5
parent 80107d3b32
commit a0bffa9467
+7 -1
View File
@@ -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);