Skip to content
Merged
Changes from all commits
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
33 changes: 30 additions & 3 deletions src/components/LazyModalSlot.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import * as Sentry from '@sentry/react-native';
import React, {Suspense} from 'react';
import {ErrorBoundary as ReactErrorBoundary} from 'react-error-boundary';
import Log from '@libs/Log';

const logModalChunkFailure = (error: Error, info: {componentStack?: string | null}) =>
Log.alert(`[GlobalModals] lazy chunk failure - ${error.message}`, {componentStack: info.componentStack ?? undefined}, false);
const isChunkLoadError = (error: Error) => error.name === 'ChunkLoadError' || /Loading chunk \S+ failed/i.test(error.message);

const logModalError = (error: Error, info: {componentStack?: string | null}) => {
const componentStack = info.componentStack ?? undefined;

if (isChunkLoadError(error)) {
/* Chunk-load failures are silent ({fallback: null}) and largely environmental
* (deploy churn, ad-blockers, flaky networks), so report as warning with a
* fixed fingerprint to keep them in one Sentry issue instead of fragmenting
* per slot/chunk. */
Log.alert(`[GlobalModals] lazy chunk failure - ${error.message}`, {componentStack}, false);
Sentry.captureException(error, {
level: 'warning',
tags: {context: 'lazy-modal-chunk'},
fingerprint: ['lazy-modal-chunk-failure'],
extra: {componentStack},
});
return;
}

// Render-phase error inside a lazy modal — a real bug. Keep default error level
// and default (stack-based) fingerprint so it surfaces alongside other crashes.
Log.alert(`[GlobalModals] modal render error - ${error.message}`, {componentStack}, false);
Sentry.captureException(error, {
tags: {context: 'lazy-modal-render-error'},
extra: {componentStack},
});
};

/**
* Wraps a lazy-loaded child in its own ErrorBoundary + Suspense pair so a chunk-load failure
Expand All @@ -13,7 +40,7 @@ function LazyModalSlot({children}: {children: React.ReactNode}) {
return (
<ReactErrorBoundary
fallback={null}
onError={logModalChunkFailure}
onError={logModalError}
>
<Suspense fallback={null}>{children}</Suspense>
</ReactErrorBoundary>
Expand Down
Loading