fix: prevent sentry from loading when telemetry is disabled (#10543)

Co-authored-by: forehalo <forehalo@gmail.com>
This commit is contained in:
hackerESQ
2025-03-05 06:09:38 -06:00
committed by GitHub
parent b247b8e26c
commit fed0e0add3
16 changed files with 122 additions and 200 deletions

View File

@@ -1,58 +1,24 @@
import './setup';
import {
init,
reactRouterV6BrowserTracingIntegration,
setTags,
} from '@sentry/react';
import { StrictMode, useEffect } from 'react';
import { Telemetry } from '@affine/core/components/telemetry';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import {
createRoutesFromChildren,
matchRoutes,
useLocation,
useNavigationType,
} from 'react-router-dom';
import { App } from './app';
function main() {
if (BUILD_CONFIG.debug || window.SENTRY_RELEASE) {
// https://docs.sentry.io/platforms/javascript/guides/react/#configure
init({
dsn: process.env.SENTRY_DSN,
environment: process.env.BUILD_TYPE ?? 'development',
integrations: [
reactRouterV6BrowserTracingIntegration({
useEffect,
useLocation,
useNavigationType,
createRoutesFromChildren,
matchRoutes,
}),
],
});
setTags({
distribution: BUILD_CONFIG.distribution,
appVersion: BUILD_CONFIG.appVersion,
editorVersion: BUILD_CONFIG.editorVersion,
});
}
mountApp();
}
function mountApp() {
// oxlint-disable-next-line @typescript-eslint/no-non-null-assertion
// oxlint-disable-next-line no-non-null-assertion
const root = document.getElementById('app')!;
createRoot(root).render(
<StrictMode>
<Telemetry />
<App />
</StrictMode>
);
}
try {
main();
mountApp();
} catch (err) {
console.error('Failed to bootstrap app', err);
}