Skip to content

Commit 0b99fa7

Browse files
chore: fix issue with non-web clients (#117)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 51ddfde commit 0b99fa7

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

.changeset/hip-mangos-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools-event-client': patch
3+
---
4+
5+
fix issue for react-native and non-web native environments for event-client

packages/event-bus-client/src/plugin.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,27 @@ export class EventClient<
119119

120120
return window
121121
}
122+
// Protect against non-web environments like react-native
123+
const eventTarget =
124+
typeof EventTarget !== 'undefined' ? new EventTarget() : undefined
125+
126+
// For non-web environments like react-native
127+
if (
128+
typeof eventTarget === 'undefined' ||
129+
typeof eventTarget.addEventListener === 'undefined'
130+
) {
131+
this.debugLog(
132+
'No event mechanism available, running in non-web environment',
133+
)
134+
return {
135+
addEventListener: () => {},
136+
removeEventListener: () => {},
137+
dispatchEvent: () => false,
138+
}
139+
}
122140

123141
this.debugLog('Using new EventTarget as fallback')
124-
return new EventTarget()
142+
return eventTarget
125143
}
126144

127145
getPluginId() {

0 commit comments

Comments
 (0)