Skip to content

fix(web): emit Sentry config as inline script tag#1459

Merged
losolio merged 1 commit into
mainfrom
fix/web-sentry-init-timing
May 18, 2026
Merged

fix(web): emit Sentry config as inline script tag#1459
losolio merged 1 commit into
mainfrom
fix/web-sentry-init-timing

Conversation

@losolio
Copy link
Copy Markdown
Contributor

@losolio losolio commented May 17, 2026

Summary

  • <Script strategy="beforeInteractive"> from next/script is rewritten in the App Router into a __next_s queue entry that runs after the client bundle — not an inline <script> in the HTML. The bundle's instrumentation-client.ts reads window.__SENTRY_CONFIG__ at module top-level, so it always saw undefined and Sentry.init never ran.
  • Render the config as a plain <script dangerouslySetInnerHTML> so it executes synchronously at HTML parse time, before any module.

Test plan

  • pnpm --filter @eventuras/web exec tsc --noEmit — clean
  • After rebuild + deploy: open browser devtools, confirm the rendered HTML contains a literal <script id="sentry-config">window.__SENTRY_CONFIG__ = {...}</script> (not a __next_s.push entry)
  • Trigger a Sentry diagnostic (admin → system page) and confirm the event lands in the Sentry project

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 17, 2026 21:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes client-side Sentry initialization in the Next.js App Router by ensuring runtime Sentry config is available before the client instrumentation module runs.

Changes:

  • Replaces next/script with a plain inline <script> for Sentry config emission.
  • Adds a changeset documenting the patch-level Sentry init timing fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
apps/web/src/providers/sentry/InitSentry.tsx Emits window.__SENTRY_CONFIG__ via an inline script in the document head.
.changeset/web-sentry-init-inline-script.md Adds patch release notes for the Sentry initialization fix.

Comment thread apps/web/src/providers/sentry/InitSentry.tsx Outdated
@losolio losolio force-pushed the fix/web-sentry-init-timing branch from c451a32 to b1d853a Compare May 17, 2026 21:15
`<Script strategy="beforeInteractive">` from next/script is rewritten
in the App Router into a `__next_s` queue entry that runs after the
client bundle, not as an inline `<script>` in the HTML. The bundle's
`instrumentation-client.ts` reads `window.__SENTRY_CONFIG__` at module
top-level, so it always saw `undefined` and `Sentry.init` never ran.

Render the config as a plain `<script dangerouslySetInnerHTML>` so it
executes synchronously at HTML parse time, before any module.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@losolio losolio force-pushed the fix/web-sentry-init-timing branch from b1d853a to 0c235ab Compare May 17, 2026 21:47
@sonarqubecloud
Copy link
Copy Markdown

@losolio losolio merged commit 2fc396e into main May 18, 2026
15 checks passed
@losolio losolio deleted the fix/web-sentry-init-timing branch May 18, 2026 17:24
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Eventuras backlog May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants