Skip to content

Commit 98d4988

Browse files
author
Luca Forstner
authored
fix: Don't depend on browser types in types (#9682)
This is a hotfix for #9679. We leaked Browser/React types into the generic `@sentry/types` package which should not have any runtime specific types.
1 parent f2e57ad commit 98d4988

File tree

7 files changed

+15
-6
lines changed

7 files changed

+15
-6
lines changed

packages/replay/src/coreHandlers/handleDom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const handleDomListener: (replay: ReplayContainer) => (handlerData: Handl
4141
handleClick(
4242
replay.clickDetector,
4343
result as Breadcrumb & { timestamp: number; data: { nodeId: number } },
44-
getClickTargetNode(handlerData.event) as HTMLElement,
44+
getClickTargetNode(handlerData.event as Event) as HTMLElement,
4545
);
4646
}
4747

@@ -97,7 +97,7 @@ function getDomTarget(handlerData: HandlerDataDom): { target: Node | null; messa
9797

9898
// Accessing event.target can throw (see getsentry/raven-js#838, #768)
9999
try {
100-
target = isClick ? getClickTargetNode(handlerData.event) : getTargetNode(handlerData.event);
100+
target = isClick ? getClickTargetNode(handlerData.event as Event) : getTargetNode(handlerData.event as Event);
101101
message = htmlTreeAsString(target, { maxStringLength: 200 }) || '<unknown>';
102102
} catch (e) {
103103
message = '<unknown>';

packages/replay/src/coreHandlers/util/domUtils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { INode } from '@sentry-internal/rrweb-snapshot';
2-
import type { HandlerDataDom } from '@sentry/types';
32

43
const INTERACTIVE_SELECTOR = 'button,a';
54

@@ -15,7 +14,7 @@ export function getClosestInteractive(element: Element): Element {
1514
* This is useful because if you click on the image in <button><img></button>,
1615
* The target will be the image, not the button, which we don't want here
1716
*/
18-
export function getClickTargetNode(event: HandlerDataDom['event'] | MouseEvent | Node): Node | INode | null {
17+
export function getClickTargetNode(event: Event | MouseEvent | Node): Node | INode | null {
1918
const target = getTargetNode(event);
2019

2120
if (!target || !(target instanceof Element)) {

packages/types/src/instrument.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export interface HandlerDataFetch {
6363
}
6464

6565
export interface HandlerDataDom {
66-
event: Event | { target: EventTarget };
66+
// TODO: Replace `object` here with a vendored type for browser Events. We can't depend on the `DOM` or `react` TS types package here.
67+
event: object | { target: object };
6768
name: string;
6869
global?: boolean;
6970
}
@@ -82,7 +83,8 @@ export interface HandlerDataError {
8283
column?: number;
8384
error?: Error;
8485
line?: number;
85-
msg: string | Event;
86+
// TODO: Replace `object` here with a vendored type for browser Events. We can't depend on the `DOM` or `react` TS types package here.
87+
msg: string | object;
8688
url?: string;
8789
}
8890

packages/utils/src/instrument/dom.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO(v8): Move everything in this file into the browser package. Nothing here is generic and we run risk of leaking browser types into non-browser packages.
2+
13
/* eslint-disable @typescript-eslint/no-explicit-any */
24
/* eslint-disable @typescript-eslint/ban-types */
35
import type { HandlerDataDom } from '@sentry/types';

packages/utils/src/instrument/history.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO(v8): Move everything in this file into the browser package. Nothing here is generic and we run risk of leaking browser types into non-browser packages.
2+
13
/* eslint-disable @typescript-eslint/no-explicit-any */
24
/* eslint-disable @typescript-eslint/ban-types */
35
import type { HandlerDataHistory } from '@sentry/types';

packages/utils/src/instrument/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO(v8): Consider moving this file (or at least parts of it) into the browser package. The registered handlers are mostly non-generic and we risk leaking runtime specific code into generic packages.
2+
13
import { DEBUG_BUILD } from '../debug-build';
24
import type {
35
InstrumentHandlerCallback as _InstrumentHandlerCallback,

packages/utils/src/instrument/xhr.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO(v8): Move everything in this file into the browser package. Nothing here is generic and we run risk of leaking browser types into non-browser packages.
2+
13
/* eslint-disable @typescript-eslint/no-explicit-any */
24
/* eslint-disable @typescript-eslint/ban-types */
35
import type { HandlerDataXhr, SentryWrappedXMLHttpRequest, WrappedFunction } from '@sentry/types';

0 commit comments

Comments
 (0)