From b46a1bb6eaf9fd22362a9fdf46cb8bab6cc5ec3b Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Mon, 20 Nov 2023 18:52:09 -0330 Subject: [PATCH] ref(feedback): Do not import window from browser pkg to avoid circular import (#9604) We will be exporting the Feedback package from the `@sentry/browser` package, so to avoid circular imports when we do, we should remove imports from `@sentry/browser` (this is what we did in Replay) --- packages/feedback/package.json | 1 - packages/feedback/src/constants.ts | 7 +++++++ packages/feedback/src/integration.ts | 2 +- packages/feedback/src/widget/Icon.ts | 3 +-- packages/feedback/src/widget/Logo.ts | 3 +-- packages/feedback/src/widget/SuccessIcon.ts | 3 +-- packages/feedback/src/widget/createShadowHost.ts | 2 +- packages/feedback/src/widget/util/createElement.ts | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/feedback/package.json b/packages/feedback/package.json index 522fcb5b4b90..0f28b1736ab7 100644 --- a/packages/feedback/package.json +++ b/packages/feedback/package.json @@ -23,7 +23,6 @@ "access": "public" }, "dependencies": { - "@sentry/browser": "7.81.0", "@sentry/core": "7.81.0", "@sentry/types": "7.81.0", "@sentry/utils": "7.81.0" diff --git a/packages/feedback/src/constants.ts b/packages/feedback/src/constants.ts index ea0db22525f4..48f699408762 100644 --- a/packages/feedback/src/constants.ts +++ b/packages/feedback/src/constants.ts @@ -1,3 +1,10 @@ +import { GLOBAL_OBJ } from '@sentry/utils'; + +// exporting a separate copy of `WINDOW` rather than exporting the one from `@sentry/browser` +// prevents the browser package from being bundled in the CDN bundle, and avoids a +// circular dependency between the browser and feedback packages +export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window; + const LIGHT_BACKGROUND = '#ffffff'; const INHERIT = 'inherit'; const SUBMIT_COLOR = 'rgba(108, 95, 199, 1)'; diff --git a/packages/feedback/src/integration.ts b/packages/feedback/src/integration.ts index 4a7bd2a7e10a..cb27042c20fc 100644 --- a/packages/feedback/src/integration.ts +++ b/packages/feedback/src/integration.ts @@ -1,4 +1,3 @@ -import { WINDOW } from '@sentry/browser'; import type { Integration } from '@sentry/types'; import { isBrowser, logger } from '@sentry/utils'; @@ -15,6 +14,7 @@ import { NAME_PLACEHOLDER, SUBMIT_BUTTON_LABEL, SUCCESS_MESSAGE_TEXT, + WINDOW, } from './constants'; import type { FeedbackInternalOptions, FeedbackWidget, OptionalFeedbackConfiguration } from './types'; import { mergeOptions } from './util/mergeOptions'; diff --git a/packages/feedback/src/widget/Icon.ts b/packages/feedback/src/widget/Icon.ts index 998eaef1ebb8..29b2d25bee8d 100644 --- a/packages/feedback/src/widget/Icon.ts +++ b/packages/feedback/src/widget/Icon.ts @@ -1,5 +1,4 @@ -import { WINDOW } from '@sentry/browser'; - +import { WINDOW } from '../constants'; import { setAttributesNS } from '../util/setAttributesNS'; const SIZE = 20; diff --git a/packages/feedback/src/widget/Logo.ts b/packages/feedback/src/widget/Logo.ts index b8c7c72b1d39..17333bda87ed 100644 --- a/packages/feedback/src/widget/Logo.ts +++ b/packages/feedback/src/widget/Logo.ts @@ -1,5 +1,4 @@ -import { WINDOW } from '@sentry/browser'; - +import { WINDOW } from '../constants'; import type { FeedbackInternalOptions } from '../types'; import { setAttributesNS } from '../util/setAttributesNS'; diff --git a/packages/feedback/src/widget/SuccessIcon.ts b/packages/feedback/src/widget/SuccessIcon.ts index 672954eae864..6092481672b9 100644 --- a/packages/feedback/src/widget/SuccessIcon.ts +++ b/packages/feedback/src/widget/SuccessIcon.ts @@ -1,5 +1,4 @@ -import { WINDOW } from '@sentry/browser'; - +import { WINDOW } from '../constants'; import { setAttributesNS } from '../util/setAttributesNS'; const WIDTH = 16; diff --git a/packages/feedback/src/widget/createShadowHost.ts b/packages/feedback/src/widget/createShadowHost.ts index bb8c0643900a..a418906d4b5a 100644 --- a/packages/feedback/src/widget/createShadowHost.ts +++ b/packages/feedback/src/widget/createShadowHost.ts @@ -1,6 +1,6 @@ -import { WINDOW } from '@sentry/browser'; import { logger } from '@sentry/utils'; +import { WINDOW } from '../constants'; import type { FeedbackInternalOptions } from '../types'; import { createDialogStyles } from './Dialog.css'; import { createMainStyles } from './Main.css'; diff --git a/packages/feedback/src/widget/util/createElement.ts b/packages/feedback/src/widget/util/createElement.ts index bf5f81868d68..e070e9a9553f 100644 --- a/packages/feedback/src/widget/util/createElement.ts +++ b/packages/feedback/src/widget/util/createElement.ts @@ -1,4 +1,4 @@ -import { WINDOW } from '@sentry/browser'; +import { WINDOW } from '../../constants'; /** * Helper function to create an element. Could be used as a JSX factory