fix(Provider): guard EIP-6963 announcement on DOM event APIs - #734
Open
oluwadareab12 wants to merge 1 commit into
Open
fix(Provider): guard EIP-6963 announcement on DOM event APIs#734oluwadareab12 wants to merge 1 commit into
oluwadareab12 wants to merge 1 commit into
Conversation
Provider.create() guarded the EIP-6963 announcement on window, CustomEvent and crypto.randomUUID, but mipd's announceProvider unconditionally calls window.dispatchEvent and window.addEventListener. In partial window-like runtimes (e.g. React Native, where window is aliased to globalThis and CustomEvent/crypto.randomUUID are polyfilled but no DOM event APIs exist) every check passed, announceProvider ran, and dispatchEvent threw "TypeError: undefined is not a function" — crashing Provider.create() entirely for any adapter, not just the announcement. Require window.dispatchEvent and window.addEventListener to be functions before announcing, so non-DOM runtimes skip the browser-only EIP-6963 announcement instead of crashing. Browser behavior is unchanged. Closes tempoxyz#730
|
@oluwadareab12 is attempting to deploy a commit to the Tempo Team on Vercel. A member of the Team first needs to authorize it. |
This was referenced Aug 12, 2026
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.
Bug
Provider.create()'s EIP-6963 announcement guarded onwindow,CustomEvent, andcrypto.randomUUID, but not on the DOM event APIs mipd'sannounceProvideractually calls:In partial
window-like runtimes (React Native/Expo, wherewindowis aliased toglobalThisandCustomEvent/crypto.randomUUIDare polyfilled for unrelated reasons but no DOM event dispatching exists), all three existing guard conditions pass,announceProviderruns, andwindow.dispatchEventthrowsTypeError: undefined is not a function— unhandled at the call site, taking downProvider.create()entirely for any adapter, not just the announcement.Fix
Extend the guard to also require
window.dispatchEventandwindow.addEventListenerto be functions:Browser behavior is unchanged. Non-DOM runtimes now silently skip the browser-only EIP-6963 announcement instead of crashing — that seemed like the only reasonable outcome here, since EIP-6963 injected-provider discovery has no meaning outside a DOM environment. Scope is intentionally limited to this guard; nothing else in
Provider.create()changed.Tests
Added
src/core/Provider.test.tscoverage (runs in thelib/pure/node project, not the browser suite, since a real browser already hasdispatchEvent):Provider.create()does not throw whenwindowexists withCustomEvent/crypto.randomUUIDbut withoutdispatchEvent/addEventListenerdispatchEventcalled) whenwindowhas both DOM event APIsBoth tests use an explicit test adapter (rather than relying on
Provider.create's defaultdialogadapter, which separately readswindow.location/window.isSecureContextfor unrelated reasons) and a randomly-generatedrdnsper call —Provider.tsdedupes announcements through a module-levelannouncedSet, so a fixedrdnswould let one test (or one of vitest's automatic retries of a prior attempt) mask another's guard behavior.Before the fix (guard reverted locally): the "skips announcement" test fails consistently across all retries with
TypeError: window.dispatchEvent is not a function, i.e. reproducing the exact crash from the issue.After the fix: all 21 tests in the file pass, including both new cases.
Also ran
tsc -b --noEmit(clean) andpnpm check(lint+fmt, 0 errors — the 2 warnings printed are pre-existing and in unrelated localnet test files).Closes #730
Saw in the issue thread that @Osraka was considering picking this up — the approach here follows exactly what was outlined there (guard on
dispatchEvent/addEventListener, keep browser behavior unchanged, focused regression test). Opened this since no PR had landed yet, but happy to hand off, adjust, or close in favor of theirs if they'd already started work I couldn't see.