Skip to content

Commit d480336

Browse files
committed
ref(replay): Export WINDOW within Replay instead of importing it from Browser
1 parent da36b2a commit d480336

17 files changed

+24
-28
lines changed

packages/replay/src/createPerformanceEntry.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { WINDOW } from '@sentry/browser';
21
import { browserPerformanceTimeOrigin } from '@sentry/utils';
32
import { record } from 'rrweb';
43

5-
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
4+
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming, WINDOW } from './types';
65
import { isIngestHost } from './util/isIngestHost';
76

87
export interface ReplayPerformanceEntry {

packages/replay/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable max-lines */ // TODO: We might want to split this file up
2-
import { WINDOW } from '@sentry/browser';
32
import { addGlobalEventProcessor, getCurrentHub, Scope, setContext } from '@sentry/core';
43
import { Breadcrumb, Client, Event, Integration } from '@sentry/types';
54
import { addInstrumentationHandler, createEnvelope, logger } from '@sentry/utils';
@@ -23,7 +22,7 @@ import { deleteSession } from './session/deleteSession';
2322
import { getSession } from './session/getSession';
2423
import { saveSession } from './session/saveSession';
2524
import { Session } from './session/Session';
26-
import type {
25+
import {
2726
AllPerformanceEntry,
2827
InstrumentationTypeBreadcrumb,
2928
InstrumentationTypeSpan,
@@ -34,6 +33,7 @@ import type {
3433
ReplayConfiguration,
3534
ReplayPluginOptions,
3635
SendReplay,
36+
WINDOW,
3737
} from './types';
3838
import { addInternalBreadcrumb } from './util/addInternalBreadcrumb';
3939
import { captureInternalException } from './util/captureInternalException';

packages/replay/src/session/deleteSession.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { WINDOW } from '@sentry/browser';
2-
1+
import { WINDOW } from '../types';
32
import { REPLAY_SESSION_KEY } from './constants';
43

54
/**

packages/replay/src/session/fetchSession.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { WINDOW } from '@sentry/browser';
2-
3-
import { SampleRates } from '../types';
1+
import { SampleRates, WINDOW } from '../types';
42
import { REPLAY_SESSION_KEY } from './constants';
53
import { Session } from './Session';
64

packages/replay/src/session/saveSession.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { WINDOW } from '@sentry/browser';
2-
1+
import { WINDOW } from '../types';
32
import { REPLAY_SESSION_KEY } from './constants';
43
import { Session } from './Session';
54

packages/replay/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import { GLOBAL_OBJ } from '@sentry/utils';
12
import type { eventWithTime, recordOptions } from 'rrweb/typings/types';
23

4+
// exporting WINDOW from within this package instead of importing it from @sentry/browser
5+
// this avoids the Browser package being bundled into the CDN bundle as well as a
6+
// circular dependency between the Browser and Replay packages in the future
7+
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;
8+
39
export type RecordingEvent = eventWithTime;
410
export type RecordingOptions = recordOptions<eventWithTime>;
511

packages/replay/src/util/isInternal.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { WINDOW } from '@sentry/browser';
2-
1+
import { WINDOW } from '../types';
32
import { isBrowser } from './isBrowser';
43

54
/**

packages/replay/test/unit/flush.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { WINDOW } from '@sentry/browser';
21
import * as SentryUtils from '@sentry/utils';
32
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';
43

4+
import { WINDOW } from '../../src/types';
55
import { Replay } from './../../src';
66
import { createPerformanceEntries } from './../../src/createPerformanceEntry';
77
import { SESSION_IDLE_DURATION } from './../../src/session/constants';

packages/replay/test/unit/index-errorSampleRate.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
jest.unmock('@sentry/browser');
22

3-
import { captureException, WINDOW } from '@sentry/browser';
3+
import { captureException } from '@sentry/browser';
44
import { BASE_TIMESTAMP, RecordMock } from '@test';
55
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
66
import { resetSdkMock } from '@test/mocks';
77
import { DomHandler, MockTransportSend } from '@test/types';
88

9+
import { WINDOW } from '../../src/types';
910
import { Replay } from './../../src';
1011
import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
1112
import { useFakeTimers } from './../utils/use-fake-timers';

packages/replay/test/unit/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
jest.mock('./../../src/util/isInternal', () => ({
22
isInternal: jest.fn(() => true),
33
}));
4-
import { WINDOW } from '@sentry/browser';
54
import { BASE_TIMESTAMP, RecordMock } from '@test';
65
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
76
import { resetSdkMock } from '@test/mocks';
@@ -10,7 +9,7 @@ import { EventType } from 'rrweb';
109

1110
import { Replay } from '../../src';
1211
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from '../../src/session/constants';
13-
import { RecordingEvent } from '../../src/types';
12+
import { RecordingEvent, WINDOW } from '../../src/types';
1413
import { useFakeTimers } from '../utils/use-fake-timers';
1514

1615
useFakeTimers();

packages/replay/test/unit/session/Session.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jest.mock('@sentry/utils', () => {
2424
});
2525

2626
import * as Sentry from '@sentry/browser';
27-
import { WINDOW } from '@sentry/browser';
2827

2928
import { Session } from '../../../src/session/Session';
29+
import { WINDOW } from '../../../src/types';
3030

3131
type CaptureEventMockType = jest.MockedFunction<typeof Sentry.captureEvent>;
3232

packages/replay/test/unit/session/createSession.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { WINDOW } from '@sentry/browser';
21
import * as Sentry from '@sentry/core';
32

43
import { createSession } from '../../../src/session/createSession';
54
import { saveSession } from '../../../src/session/saveSession';
5+
import { WINDOW } from '../../../src/types';
66

77
jest.mock('./../../../src/session/saveSession');
88

packages/replay/test/unit/session/deleteSession.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { WINDOW } from '@sentry/browser';
2-
31
import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
42
import { deleteSession } from '../../../src/session/deleteSession';
3+
import { WINDOW } from '../../../src/types';
54

65
const storageEngine = WINDOW.sessionStorage;
76

packages/replay/test/unit/session/fetchSession.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { WINDOW } from '@sentry/browser';
2-
31
import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
42
import { fetchSession } from '../../../src/session/fetchSession';
3+
import { WINDOW } from '../../../src/types';
54

65
const oldSessionStorage = WINDOW.sessionStorage;
76

packages/replay/test/unit/session/getSession.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { WINDOW } from '@sentry/browser';
2-
31
import * as CreateSession from '../../../src/session/createSession';
42
import * as FetchSession from '../../../src/session/fetchSession';
53
import { getSession } from '../../../src/session/getSession';
64
import { saveSession } from '../../../src/session/saveSession';
75
import { Session } from '../../../src/session/Session';
6+
import { WINDOW } from '../../../src/types';
87

98
jest.mock('@sentry/utils', () => {
109
return {

packages/replay/test/unit/session/saveSession.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { WINDOW } from '@sentry/browser';
2-
31
import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
42
import { saveSession } from '../../../src/session/saveSession';
53
import { Session } from '../../../src/session/Session';
4+
import { WINDOW } from '../../../src/types';
65

76
beforeAll(() => {
87
WINDOW.sessionStorage.clear();

packages/replay/test/unit/stop.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { WINDOW } from '@sentry/browser';
21
import * as SentryUtils from '@sentry/utils';
32
// mock functions need to be imported first
43
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';
54

5+
import { WINDOW } from '../../src/types';
66
import { Replay } from './../../src';
77
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
88
import { useFakeTimers } from './../utils/use-fake-timers';

0 commit comments

Comments
 (0)