Skip to content

Commit 7a904c7

Browse files
committed
fix(feedback): Fix an issue where, if removeFromDom() is called it might throw
1 parent d007407 commit 7a904c7

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Diff for: packages/feedback/src/core/components/Actor.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { DEBUG_BUILD } from 'src/util/debug-build';
12
import { DOCUMENT, TRIGGER_LABEL } from '../../constants';
23
import { createActorStyles } from './Actor.css';
34
import { FeedbackIcon } from './FeedbackIcon';
5+
import { logger } from '@sentry/core';
46

57
export interface ActorProps {
68
triggerLabel: string;
@@ -46,8 +48,16 @@ export function Actor({ triggerLabel, triggerAriaLabel, shadow, styleNonce }: Ac
4648
shadow.appendChild(el);
4749
},
4850
removeFromDom(): void {
49-
shadow.removeChild(el);
50-
shadow.removeChild(style);
51+
try {
52+
el.remove();
53+
style.remove();
54+
} catch {
55+
DEBUG_BUILD &&
56+
logger.error(
57+
'[Feedback] Error when trying to remove Actor from the DOM. It is not appended to the DOM yet!',
58+
);
59+
throw new Error('[Feedback] Actor is not appended to DOM, nothing to remove.');
60+
}
5161
},
5262
show(): void {
5363
el.ariaHidden = 'false';

Diff for: packages/feedback/src/modal/integration.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as hooks from 'preact/hooks';
55
import { DOCUMENT } from '../constants';
66
import { Dialog } from './components/Dialog';
77
import { createDialogStyles } from './components/Dialog.css';
8+
import { DEBUG_BUILD } from 'src/util/debug-build';
9+
import { logger } from '@sentry/core';
810

911
function getUser(): User | undefined {
1012
const currentUser = getCurrentScope().getUser();
@@ -44,8 +46,14 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => {
4446
}
4547
},
4648
removeFromDom(): void {
47-
shadowRoot.removeChild(el);
48-
shadowRoot.removeChild(style);
49+
try {
50+
el.remove();
51+
style.remove();
52+
} catch {
53+
DEBUG_BUILD &&
54+
logger.error('[Feedback] Error when trying to remove Modal from the DOM. It is not appended to the DOM yet!');
55+
throw new Error('[Feedback] Modal is not appended to DOM, nothing to remove.');
56+
}
4957
DOCUMENT.body.style.overflow = originalOverflow;
5058
},
5159
open() {

0 commit comments

Comments
 (0)