Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

The online/offline checker now presumes that globalThis is the event target #3658

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-zoos-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/rpc-subscriptions': patch
---

The online/offline checker in the subscriptions implementation no longer throws an error when hosted in the Content Scripts environment of a browser extension
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('getRpcSubscriptionsChannelWithAutoping', () => {
let mockOn: jest.Mock;
let mockSend: jest.Mock;
let mockWindowAddEventListener: jest.Mock;
let originalWindowAddEventListener: typeof globalThis.window.addEventListener;
let originalWindowAddEventListener: typeof globalThis.addEventListener;
function receiveError(error?: unknown) {
mockOn.mock.calls.filter(([type]) => type === 'error').forEach(([_, listener]) => listener(error));
}
Expand All @@ -25,8 +25,8 @@ describe('getRpcSubscriptionsChannelWithAutoping', () => {
beforeEach(() => {
jest.useFakeTimers();
if (__BROWSER__) {
originalWindowAddEventListener = globalThis.window.addEventListener;
globalThis.window.addEventListener = mockWindowAddEventListener = jest.fn();
originalWindowAddEventListener = globalThis.addEventListener;
globalThis.addEventListener = mockWindowAddEventListener = jest.fn();
}
mockOn = jest.fn().mockReturnValue(() => {});
mockSend = jest.fn().mockResolvedValue(void 0);
Expand All @@ -37,7 +37,7 @@ describe('getRpcSubscriptionsChannelWithAutoping', () => {
});
afterEach(() => {
if (__BROWSER__) {
globalThis.window.addEventListener = originalWindowAddEventListener;
globalThis.addEventListener = originalWindowAddEventListener;
}
});
it('sends a ping message to the channel at the specified interval', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export function getRpcSubscriptionsChannelWithAutoping<TChannel extends RpcSubsc
restartPingTimer();
}
if (__BROWSER__) {
globalThis.window.addEventListener(
globalThis.addEventListener(
'offline',
function handleOffline() {
clearInterval(intervalId);
},
{ signal: pingerAbortController.signal },
);
globalThis.window.addEventListener(
globalThis.addEventListener(
'online',
function handleOnline() {
sendPing();
Expand Down
Loading