Skip to content

Commit e7996b8

Browse files
antonisclaude
andcommitted
fix(feedback): Guard against shake listener crashes and asymmetric lifecycle
- Wrap stopShakeListener native calls in try/catch so exceptions from subscription.remove() or disableShakeDetection() never crash the app. - Guard enableFeedbackOnShake so repeated calls don't overwrite _imperativeShakeListenerStarted with false, which would make disableFeedbackOnShake a permanent no-op. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1d515e7 commit e7996b8

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/core/src/js/feedback/FeedbackWidgetManager.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ let _imperativeShakeListenerStarted = false;
137137

138138
const enableFeedbackOnShake = (): void => {
139139
lazyLoadAutoInjectFeedbackIntegration();
140-
_imperativeShakeListenerStarted = startShakeListener(showFeedbackWidget);
140+
if (!_imperativeShakeListenerStarted) {
141+
_imperativeShakeListenerStarted = startShakeListener(showFeedbackWidget);
142+
}
141143
};
142144

143145
const disableFeedbackOnShake = (): void => {

packages/core/src/js/feedback/ShakeToReportBug.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,19 @@ export function startShakeListener(
7373
*/
7474
export function stopShakeListener(): void {
7575
if (_shakeSubscription) {
76-
_shakeSubscription.remove();
76+
try {
77+
_shakeSubscription.remove();
78+
} catch (e) {
79+
debug.warn('Failed to remove shake subscription:', e);
80+
}
7781
_shakeSubscription = null;
7882

79-
const nativeModule = getRNSentryModule() as { disableShakeDetection?: () => void } | undefined;
80-
nativeModule?.disableShakeDetection?.();
83+
try {
84+
const nativeModule = getRNSentryModule() as { disableShakeDetection?: () => void } | undefined;
85+
nativeModule?.disableShakeDetection?.();
86+
} catch (e) {
87+
debug.warn('Failed to disable native shake detection:', e);
88+
}
8189
}
8290
}
8391

0 commit comments

Comments
 (0)