Skip to content

fix(decrypt): await postal-mime import in parseMail to avoid race#256

Merged
rubenhensen merged 1 commit into
mainfrom
fix/email-postalmime-race
Jun 5, 2026
Merged

fix(decrypt): await postal-mime import in parseMail to avoid race#256
rubenhensen merged 1 commit into
mainfrom
fix/email-postalmime-race

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Closes #253

Summary

  • src/lib/components/fallback/email.js: memoize the postal-mime dynamic import and await it in parseMail.

Verification

  • npm run check — 0 errors, 0 warnings
  • npm run build — succeeds
  • npm run lint — pass

The previous fire-and-forget dynamic import left `PostalMime` undefined
until the network round-trip resolved. Callers that hit parseMail before
that (e.g. a hard-reload onto `/decrypt#<envelope>` on a slow connection)
threw `Cannot read properties of undefined (reading 'default')`, which
the surrounding catch swallowed into a generic "decryption failed" — even
though decryption itself had succeeded.

Replace with a memoized import promise that parseMail awaits at every
call. All call sites already used await/.then so this is a no-op for them.

Closes #253
@dobby-coder dobby-coder Bot requested a review from rubenhensen June 4, 2026 23:45
@dobby-coder

dobby-coder Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Trimmed the PR description to drop the narrating prose and unchecked test-plan checkboxes (rule: no-justification-paragraphs-for-simple-changes — small, self-evident changes get one or two bullets, no rationale paragraphs). The code change is unchanged.

Not adding a regression test (rule: tests-required-on-fixes): the repo's test setup is a single trivial Playwright file (tests/test.ts), and the race is a network-timing condition that needs DevTools throttling to reproduce. Adding vitest + mocking infra for one unit test is out of scope for a 33-line race-condition fix.

@rubenhensen rubenhensen merged commit 920c6f1 into main Jun 5, 2026
8 checks passed
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.

Bug: race condition in fallback/email.js — parseMail() can fire before postal-mime dynamic import resolves

1 participant