From d552f5f4f297cc9361b4987e1b2a2867e8c8bd4e Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Wed, 15 Jul 2026 22:07:23 +0300 Subject: [PATCH] Work --- app/entry.client.tsx | 18 +++++++++++++++--- vite.config.ts | 9 +++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/entry.client.tsx b/app/entry.client.tsx index 2edce725a..f056e5c35 100644 --- a/app/entry.client.tsx +++ b/app/entry.client.tsx @@ -100,12 +100,22 @@ if ("serviceWorker" in navigator) { }); } +/** + * Max time hydration waits for Sentry to initialize. If Sentry loads within + * this window its instrumentation is passed to the router (enabling the + * pageload trace); if not, hydration proceeds without it and errors are still + * captured once Sentry finishes loading. + */ +const SENTRY_INIT_TIMEOUT_MS = 1000; + +const sentryPromise = initSentry(); + // the server rendered with the page language's date-fns locale, so it must be // cached before hydration to avoid a markup mismatch Promise.all([ i18nLoader(), loadDateFnsLocale(document.documentElement.lang as LanguageCode), - initSentry(), + Promise.race([sentryPromise, wait(SENTRY_INIT_TIMEOUT_MS)]), ]) .then(([, , sentry]) => hydrateRoot( @@ -116,8 +126,10 @@ Promise.all([ sentry ? [sentry.tracing.clientInstrumentation] : [] } onError={(error) => { - if (sentry && error instanceof Error) { - sentry.captureException(error); + if (error instanceof Error) { + void sentryPromise.then((sentry) => + sentry?.captureException(error), + ); } }} /> diff --git a/vite.config.ts b/vite.config.ts index 7e3b625cf..241b518c0 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -48,6 +48,15 @@ export default defineConfig((config) => { telemetry: false, unstable_sentryVitePluginOptions: { applicationKey: "sendou-ink", + // tree-shakes SDK features we don't use (Replay, debug logging) + // out of the dynamically imported client bundle + bundleSizeOptimizations: { + excludeDebugStatements: true, + excludeReplayCanvas: true, + excludeReplayShadowDom: true, + excludeReplayIframe: true, + excludeReplayWorker: true, + }, }, }, config,