Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(replay): Export WINDOW within Replay instead of importing it from Browser #6386

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions packages/replay/src/createPerformanceEntry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { WINDOW } from '@sentry/browser';
import { browserPerformanceTimeOrigin } from '@sentry/utils';
import { record } from 'rrweb';

import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming } from './types';
import { AllPerformanceEntry, PerformanceNavigationTiming, PerformancePaintTiming, WINDOW } from './types';
import { isIngestHost } from './util/isIngestHost';

export interface ReplayPerformanceEntry {
Expand Down
4 changes: 2 additions & 2 deletions packages/replay/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable max-lines */ // TODO: We might want to split this file up
import { WINDOW } from '@sentry/browser';
import { addGlobalEventProcessor, getCurrentHub, Scope, setContext } from '@sentry/core';
import { Breadcrumb, Client, Event, Integration } from '@sentry/types';
import { addInstrumentationHandler, createEnvelope, logger } from '@sentry/utils';
Expand All @@ -23,7 +22,7 @@ import { deleteSession } from './session/deleteSession';
import { getSession } from './session/getSession';
import { saveSession } from './session/saveSession';
import { Session } from './session/Session';
import type {
import {
AllPerformanceEntry,
InstrumentationTypeBreadcrumb,
InstrumentationTypeSpan,
Expand All @@ -34,6 +33,7 @@ import type {
ReplayConfiguration,
ReplayPluginOptions,
SendReplay,
WINDOW,
} from './types';
import { addInternalBreadcrumb } from './util/addInternalBreadcrumb';
import { captureInternalException } from './util/captureInternalException';
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/src/session/deleteSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { WINDOW } from '../types';
import { REPLAY_SESSION_KEY } from './constants';

/**
Expand Down
4 changes: 1 addition & 3 deletions packages/replay/src/session/fetchSession.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { SampleRates } from '../types';
import { SampleRates, WINDOW } from '../types';
import { REPLAY_SESSION_KEY } from './constants';
import { Session } from './Session';

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/src/session/saveSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { WINDOW } from '../types';
import { REPLAY_SESSION_KEY } from './constants';
import { Session } from './Session';

Expand Down
6 changes: 6 additions & 0 deletions packages/replay/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { GLOBAL_OBJ } from '@sentry/utils';
import type { eventWithTime, recordOptions } from 'rrweb/typings/types';

// exporting WINDOW from within this package instead of importing it from @sentry/browser
// this avoids the Browser package being bundled into the CDN bundle as well as a
// circular dependency between the Browser and Replay packages in the future
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;
Lms24 marked this conversation as resolved.
Show resolved Hide resolved

export type RecordingEvent = eventWithTime;
export type RecordingOptions = recordOptions<eventWithTime>;

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/src/util/isInternal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WINDOW } from '@sentry/browser';

import { WINDOW } from '../types';
import { isBrowser } from './isBrowser';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/flush.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WINDOW } from '@sentry/browser';
import * as SentryUtils from '@sentry/utils';
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { WINDOW } from '../../src/types';
import { Replay } from './../../src';
import { createPerformanceEntries } from './../../src/createPerformanceEntry';
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
Expand Down
3 changes: 2 additions & 1 deletion packages/replay/test/unit/index-errorSampleRate.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
jest.unmock('@sentry/browser');

import { captureException, WINDOW } from '@sentry/browser';
import { captureException } from '@sentry/browser';
import { BASE_TIMESTAMP, RecordMock } from '@test';
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
import { resetSdkMock } from '@test/mocks';
import { DomHandler, MockTransportSend } from '@test/types';

import { WINDOW } from '../../src/types';
import { Replay } from './../../src';
import { REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
jest.mock('./../../src/util/isInternal', () => ({
isInternal: jest.fn(() => true),
}));
import { WINDOW } from '@sentry/browser';
import { BASE_TIMESTAMP, RecordMock } from '@test';
import { PerformanceEntryResource } from '@test/fixtures/performanceEntry/resource';
import { resetSdkMock } from '@test/mocks';
Expand All @@ -10,7 +9,7 @@ import { EventType } from 'rrweb';

import { Replay } from '../../src';
import { MAX_SESSION_LIFE, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT } from '../../src/session/constants';
import { RecordingEvent } from '../../src/types';
import { RecordingEvent, WINDOW } from '../../src/types';
import { useFakeTimers } from '../utils/use-fake-timers';

useFakeTimers();
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/session/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jest.mock('@sentry/utils', () => {
});

import * as Sentry from '@sentry/browser';
import { WINDOW } from '@sentry/browser';

import { Session } from '../../../src/session/Session';
import { WINDOW } from '../../../src/types';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/session/createSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WINDOW } from '@sentry/browser';
import * as Sentry from '@sentry/core';

import { createSession } from '../../../src/session/createSession';
import { saveSession } from '../../../src/session/saveSession';
import { WINDOW } from '../../../src/types';

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

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/deleteSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { deleteSession } from '../../../src/session/deleteSession';
import { WINDOW } from '../../../src/types';

const storageEngine = WINDOW.sessionStorage;

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/fetchSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { fetchSession } from '../../../src/session/fetchSession';
import { WINDOW } from '../../../src/types';

const oldSessionStorage = WINDOW.sessionStorage;

Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/getSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { WINDOW } from '@sentry/browser';

import * as CreateSession from '../../../src/session/createSession';
import * as FetchSession from '../../../src/session/fetchSession';
import { getSession } from '../../../src/session/getSession';
import { saveSession } from '../../../src/session/saveSession';
import { Session } from '../../../src/session/Session';
import { WINDOW } from '../../../src/types';

jest.mock('@sentry/utils', () => {
return {
Expand Down
3 changes: 1 addition & 2 deletions packages/replay/test/unit/session/saveSession.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { WINDOW } from '@sentry/browser';

import { REPLAY_SESSION_KEY } from '../../../src/session/constants';
import { saveSession } from '../../../src/session/saveSession';
import { Session } from '../../../src/session/Session';
import { WINDOW } from '../../../src/types';

beforeAll(() => {
WINDOW.sessionStorage.clear();
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/test/unit/stop.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WINDOW } from '@sentry/browser';
import * as SentryUtils from '@sentry/utils';
// mock functions need to be imported first
import { BASE_TIMESTAMP, mockRrweb, mockSdk } from '@test';

import { WINDOW } from '../../src/types';
import { Replay } from './../../src';
import { SESSION_IDLE_DURATION } from './../../src/session/constants';
import { useFakeTimers } from './../utils/use-fake-timers';
Expand Down