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 20:09:38 +08:00
committed by GitHub
co-authored by forehalo
parent b247b8e26c
commit fed0e0add3
16 changed files with 122 additions and 200 deletions
+5 -39
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);
}
@@ -1,46 +1,13 @@
import './setup';
import { appConfigProxy } from '@affine/core/components/hooks/use-app-config-storage';
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() {
// skip bootstrap setup for desktop onboarding
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,
});
}
// load persistent config for electron
// TODO(@Peng): should be sync, but it's not necessary for now
appConfigProxy
@@ -55,6 +22,7 @@ function mountApp() {
const root = document.getElementById('app')!;
createRoot(root).render(
<StrictMode>
<Telemetry />
<App />
</StrictMode>
);
+4 -38
View File
@@ -2,20 +2,10 @@ import './setup';
import '@affine/component/theme';
import '@affine/core/mobile/styles/mobile.css';
import { Telemetry } from '@affine/core/components/telemetry';
import { bindNativeDBApis } from '@affine/nbstore/sqlite';
import {
init,
reactRouterV6BrowserTracingIntegration,
setTags,
} from '@sentry/react';
import { StrictMode, useEffect } from 'react';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import {
createRoutesFromChildren,
matchRoutes,
useLocation,
useNavigationType,
} from 'react-router-dom';
import { App } from './app';
import { NbStoreNativeDBApis } from './plugins/nbstore';
@@ -25,43 +15,19 @@ bindNativeDBApis(NbStoreNativeDBApis);
// TODO(@L-Sun) Uncomment this when the `show` method implement by `@capacitor/keyboard` in ios
// import './virtual-keyboard';
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
const root = document.getElementById('app')!;
createRoot(root).render(
<StrictMode>
<Telemetry />
<App />
</StrictMode>
);
}
try {
main();
mountApp();
} catch (err) {
console.error('Failed to bootstrap app', err);
}
+4 -38
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 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);
}
+1
View File
@@ -13,6 +13,7 @@
"@affine/core": "workspace:*",
"@affine/i18n": "workspace:*",
"@affine/nbstore": "workspace:*",
"@affine/track": "workspace:*",
"@emotion/react": "^11.14.0",
"@sentry/react": "^9.2.0",
"@toeverything/infra": "workspace:*",
+4 -40
View File
@@ -1,60 +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() {
// skip bootstrap setup for desktop onboarding
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
const root = document.getElementById('app')!;
createRoot(root).render(
<StrictMode>
<Telemetry />
<App />
</StrictMode>
);
}
try {
main();
mountApp();
} catch (err) {
console.error('Failed to bootstrap app', err);
}