fix(postMessage): guard session warm-up on document availability - #762
Open
erhnysr wants to merge 1 commit into
Open
fix(postMessage): guard session warm-up on document availability#762erhnysr wants to merge 1 commit into
erhnysr wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@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
force-pushed
the
fix/postmessage-document-guard
branch
from
August 30, 2026 13:13
e1c227d to
dff778f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
postMessage.ts:249readsdocument.bodybehind awindow-only guard:In a runtime that exposes
windowwithoutdocument— React Native and Expo — that read throws before the surroundingtry {} catch {}can absorb it, so the session warm-up crashes instead of being skipped.AGENTS.md:105 documents this exact footgun:
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
documentbefore touchingdocument.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, thewindow-without-documentcase 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 lintreports two pre-existing warnings inexchange.localnet.test.ts:599andpostMessage.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.