Skip to content

Commit 8e94898

Browse files
authored
ref(replay): Export WINDOW within Replay instead of importing it from Browser (#6386)
In preparation to generating CDN bundles, this change copies the `WINDOW` constant declaration from `@sentry/browser` to the Replay package and updates the imports to use the package-internal version of `WINDOW`. This has two advantages: * When building CDN bundles, we don't bundle contents from `@sentry/browser` anymore. This previously caused the generated bundles to not work correctly and it unnecessarily increased bundle size * By not importing anything from `@sentry/browser` we avoid a circular dependency one we export the Replay integration from the Browser SDK.
1 parent 1e78eb6 commit 8e94898

20 files changed

+33
-43
lines changed

packages/replay/src/session/constants.ts renamed to packages/replay/src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import { GLOBAL_OBJ } from '@sentry/utils';
2+
3+
// exporting WINDOW from within the @sentry/replay instead of importing it from @sentry/browser
4+
// this avoids the Browser package being bundled into the CDN bundle as well as a
5+
// circular dependency between the Browser and Replay packages in the future
6+
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;
7+
18
export const REPLAY_SESSION_KEY = 'sentryReplaySession';
29
export const REPLAY_EVENT_NAME = 'replay_event';
310
export const RECORDING_EVENT_NAME = 'replay_recording';

packages/replay/src/createPerformanceEntry.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 { browserPerformanceTimeOrigin } from '@sentry/utils';
32
import { record } from 'rrweb';
43

4+
import { WINDOW } from './constants';
55
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
66
import { isIngestHost } from './util/isIngestHost';
77

packages/replay/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
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';
65
import debounce from 'lodash.debounce';
76
import { PerformanceObserverEntryList } from 'perf_hooks';
87
import { EventType, record } from 'rrweb';
98

10-
import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler';
11-
import { spanHandler } from './coreHandlers/spanHandler';
12-
import { createMemoryEntry, createPerformanceEntries, ReplayPerformanceEntry } from './createPerformanceEntry';
13-
import { createEventBuffer, IEventBuffer } from './eventBuffer';
149
import {
1510
DEFAULT_ERROR_SAMPLE_RATE,
1611
DEFAULT_SESSION_SAMPLE_RATE,
1712
MAX_SESSION_LIFE,
1813
REPLAY_EVENT_NAME,
1914
SESSION_IDLE_DURATION,
2015
VISIBILITY_CHANGE_TIMEOUT,
21-
} from './session/constants';
16+
WINDOW,
17+
} from './constants';
18+
import { breadcrumbHandler } from './coreHandlers/breadcrumbHandler';
19+
import { spanHandler } from './coreHandlers/spanHandler';
20+
import { createMemoryEntry, createPerformanceEntries, ReplayPerformanceEntry } from './createPerformanceEntry';
21+
import { createEventBuffer, IEventBuffer } from './eventBuffer';
2222
import { deleteSession } from './session/deleteSession';
2323
import { getSession } from './session/getSession';
2424
import { saveSession } from './session/saveSession';
2525
import { Session } from './session/Session';
26-
import type {
26+
import {
2727
AllPerformanceEntry,
2828
InstrumentationTypeBreadcrumb,
2929
InstrumentationTypeSpan,

packages/replay/src/session/deleteSession.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 { REPLAY_SESSION_KEY } from './constants';
1+
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
42

53
/**
64
* Deletes a session from storage

packages/replay/src/session/fetchSession.ts

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

75
/**

packages/replay/src/session/saveSession.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 { REPLAY_SESSION_KEY } from './constants';
1+
import { REPLAY_SESSION_KEY, WINDOW } from '../constants';
42
import { Session } from './Session';
53

64
export function saveSession(session: Session): void {

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 '../constants';
32
import { isBrowser } from './isBrowser';
43

54
/**

packages/replay/src/util/isSessionExpired.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MAX_SESSION_LIFE } from '../session/constants';
1+
import { MAX_SESSION_LIFE } from '../constants';
22
import { Session } from '../session/Session';
33
import { isExpired } from './isExpired';
44

packages/replay/test/unit/flush.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';
21
import * as SentryUtils from '@sentry/utils';
32
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';
43

4+
import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
55
import { Replay } from './../../src';
66
import { createPerformanceEntries } from './../../src/createPerformanceEntry';
7-
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
87
import { useFakeTimers } from './../../test/utils/use-fake-timers';
98

109
useFakeTimers();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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 { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
910
import { Replay } from './../../src';
10-
import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
1111
import { useFakeTimers } from './../utils/use-fake-timers';
1212

1313
useFakeTimers();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Error } from '@test/fixtures/error';
22
import { Transaction } from '@test/fixtures/transaction';
33
import { resetSdkMock } from '@test/mocks';
44

5+
import { REPLAY_EVENT_NAME } from '../../src/constants';
56
import { Replay } from './../../src';
6-
import { REPLAY_EVENT_NAME } from './../../src/session/constants';
77
import { useFakeTimers } from './../utils/use-fake-timers';
88

99
useFakeTimers();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Transport } from '@sentry/types';
33
import * as SentryUtils from '@sentry/utils';
44
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';
55

6+
import { SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from '../../src/constants';
67
import { Replay } from './../../src';
7-
import { SESSION_IDLE_DURATION, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
88
import { useFakeTimers } from './../utils/use-fake-timers';
99

1010
useFakeTimers();

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
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';
87
import { DomHandler, MockTransportSend } from '@test/types';
98
import { EventType } from 'rrweb';
109

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

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

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

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

28+
import { WINDOW } from '../../../src/constants';
2929
import { Session } from '../../../src/session/Session';
3030

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

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

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

3+
import { WINDOW } from '../../../src/constants';
44
import { createSession } from '../../../src/session/createSession';
55
import { saveSession } from '../../../src/session/saveSession';
66

packages/replay/test/unit/session/deleteSession.test.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 { REPLAY_SESSION_KEY } from '../../../src/session/constants';
1+
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
42
import { deleteSession } from '../../../src/session/deleteSession';
53

64
const storageEngine = WINDOW.sessionStorage;

packages/replay/test/unit/session/fetchSession.test.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 { REPLAY_SESSION_KEY } from '../../../src/session/constants';
1+
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
42
import { fetchSession } from '../../../src/session/fetchSession';
53

64
const oldSessionStorage = WINDOW.sessionStorage;

packages/replay/test/unit/session/getSession.test.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 '../../../src/constants';
32
import * as CreateSession from '../../../src/session/createSession';
43
import * as FetchSession from '../../../src/session/fetchSession';
54
import { getSession } from '../../../src/session/getSession';

packages/replay/test/unit/session/saveSession.test.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 { REPLAY_SESSION_KEY } from '../../../src/session/constants';
1+
import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
42
import { saveSession } from '../../../src/session/saveSession';
53
import { Session } from '../../../src/session/Session';
64

packages/replay/test/unit/stop.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';
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 { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
66
import { Replay } from './../../src';
7-
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
87
import { useFakeTimers } from './../utils/use-fake-timers';
98

109
useFakeTimers();

0 commit comments

Comments
 (0)