Skip to content

fix(postMessage): guard session warm-up on document availability - #762

Open
erhnysr wants to merge 1 commit into
tempoxyz:mainfrom
erhnysr:fix/postmessage-document-guard
Open

fix(postMessage): guard session warm-up on document availability#762
erhnysr wants to merge 1 commit into
tempoxyz:mainfrom
erhnysr:fix/postmessage-document-guard

Conversation

@erhnysr

@erhnysr erhnysr commented Aug 14, 2026

Copy link
Copy Markdown

Problem

postMessage.ts:249 reads document.body behind a window-only guard:

if (typeof window !== 'undefined' && !target && document.body)

In a runtime that exposes window without document — React Native and Expo — that read throws before the surrounding try {} catch {} can absorb it, so the session warm-up crashes instead of being skipped.

AGENTS.md:105 documents this exact footgun:

React Native may expose window without browser event constructors… must guard on both window and [the capability] before calling browser-only helpers.

Line 106 states the storage variant of the same rule, which is what my #759 addresses. This is the DOM instance of it.

Fix

Guard on document before touching document.body, matching the shape the rule prescribes and the sibling guard fixes #706 (crypto.randomUUID) and #734 (partial-window announcement) already use.

One line.

Tests

Two cases in src/core/adapters/postMessage/postMessage.test.ts. Verified failing-first: before the change, the window-without-document case throws.

Suite goes 569 → 571 passing, 33 → 34 files.

Changeset

patch, matching #706 and #734 — no new API, a crash becomes a skipped warm-up.

Note on lint

vp lint reports two pre-existing warnings in exchange.localnet.test.ts:599 and postMessage.localnet.test.ts:609. Neither is in my diff; both predate this change.

Localnet tests weren't run locally — they need a Docker RPC node, and this change is browser/RN-only with no localnet surface.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

@erhnysr is attempting to deploy a commit to the Tempo Team on Vercel.

A member of the Team first needs to authorize it.

`postMessage`'s pre-request warm-up checked `typeof window !== 'undefined'`
but then dereferenced bare `document.body`. In partial `window`-like runtimes
(React Native/Expo) `window` exists without `document`, so `postMessage()` and
`tempoWallet()` threw `ReferenceError: document is not defined` at creation.

Guard on `typeof document !== 'undefined'` before touching `document.body`,
matching the shape prescribed in AGENTS.md and used by tempoxyz#706/tempoxyz#734.
@erhnysr
erhnysr force-pushed the fix/postmessage-document-guard branch from e1c227d to dff778f Compare August 30, 2026 13:13
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