fix(web): emit Sentry config as inline script tag#1459
Merged
Conversation
Contributor
There was a problem hiding this comment.
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/scriptwith 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. |
c451a32 to
b1d853a
Compare
`<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>
b1d853a to
0c235ab
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
<Script strategy="beforeInteractive">fromnext/scriptis rewritten in the App Router into a__next_squeue entry that runs after the client bundle — not an inline<script>in the HTML. The bundle'sinstrumentation-client.tsreadswindow.__SENTRY_CONFIG__at module top-level, so it always sawundefinedandSentry.initnever ran.<script dangerouslySetInnerHTML>so it executes synchronously at HTML parse time, before any module.Test plan
pnpm --filter @eventuras/web exec tsc --noEmit— clean<script id="sentry-config">window.__SENTRY_CONFIG__ = {...}</script>(not a__next_s.pushentry)🤖 Generated with Claude Code