Repository navigation
fix(react-router): Pass the release to the browser in the page #26508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
isaacs
merged 3 commits into
fix/remix-release-runtime
from
fix/react-router-release-runtime
Nov 18, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
7484cdb
fix(react-router): Pass the release to the browser in the page
sentry-junior[bot] 90221b3
fix(react-router): Resolve the client release after loading the build…
sentry-junior[bot] 4f75acd
fix(react-router): Set the server release from the server build
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/react-router-7-framework-spa/tests/constants.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| export const APP_NAME = 'react-router-7-framework-spa'; | ||
|
|
||
| // Set in `vite.config.ts`. | ||
| export const RELEASE = 'react-router-7-framework-spa-e2e'; |
25 changes: 25 additions & 0 deletions
25
...es/e2e-tests/test-applications/react-router-7-framework-spa/tests/release/release.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { readdirSync, readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { expect, test } from '@playwright/test'; | ||
| import { RELEASE } from '../constants'; | ||
|
|
||
| const CLIENT_BUILD = path.join(process.cwd(), 'build/client'); | ||
|
|
||
| test.describe('release', () => { | ||
| test('is in the SPA fallback page that the build renders', () => { | ||
| const html = readFileSync(path.join(CLIENT_BUILD, 'index.html'), 'utf8'); | ||
|
|
||
| expect(html).toContain(`<meta name="sentry-release" content="${RELEASE}"/>`); | ||
| }); | ||
|
|
||
| test('is not in the content-hashed client assets', () => { | ||
| expect(filesContaining(path.join(CLIENT_BUILD, 'assets'), RELEASE)).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| function filesContaining(dir: string, text: string): string[] { | ||
| return readdirSync(dir, { recursive: true, withFileTypes: true }) | ||
| .filter(entry => entry.isFile()) | ||
| .map(entry => path.join(entry.parentPath, entry.name)) | ||
| .filter(file => readFileSync(file, 'utf8').includes(text)); | ||
| } |
13 changes: 11 additions & 2 deletions
13
dev-packages/e2e-tests/test-applications/react-router-7-framework-spa/vite.config.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,15 @@ | ||
| import { reactRouter } from '@react-router/dev/vite'; | ||
| import { sentryReactRouter } from '@sentry/react-router/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [reactRouter()], | ||
| export default defineConfig(config => { | ||
| return { | ||
| plugins: [ | ||
| reactRouter(), | ||
| sentryReactRouter( | ||
| { release: { name: 'react-router-7-framework-spa-e2e' }, sourcemaps: { disable: true } }, | ||
| config, | ||
| ), | ||
| ], | ||
| }; | ||
| }); |
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/react-router-7-framework/tests/constants.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| export const APP_NAME = 'react-router-7-framework'; | ||
|
|
||
| // Set in `vite.config.ts`. | ||
| export const RELEASE = 'react-router-7-framework-e2e'; |
25 changes: 25 additions & 0 deletions
25
...ckages/e2e-tests/test-applications/react-router-7-framework/tests/release/release.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { readdirSync, readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { expect, test } from '@playwright/test'; | ||
| import { RELEASE } from '../constants'; | ||
|
|
||
| const CLIENT_BUILD = path.join(process.cwd(), 'build/client'); | ||
|
|
||
| test.describe('release', () => { | ||
| test('is in the page that the build prerenders', () => { | ||
| const html = readFileSync(path.join(CLIENT_BUILD, 'performance/static/index.html'), 'utf8'); | ||
|
|
||
| expect(html).toContain(`<meta name="sentry-release" content="${RELEASE}"/>`); | ||
| }); | ||
|
|
||
| test('is not in the content-hashed client assets', () => { | ||
| expect(filesContaining(path.join(CLIENT_BUILD, 'assets'), RELEASE)).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| function filesContaining(dir: string, text: string): string[] { | ||
| return readdirSync(dir, { recursive: true, withFileTypes: true }) | ||
| .filter(entry => entry.isFile()) | ||
| .map(entry => path.join(entry.parentPath, entry.name)) | ||
| .filter(file => readFileSync(file, 'utf8').includes(text)); | ||
| } |
18 changes: 16 additions & 2 deletions
18
dev-packages/e2e-tests/test-applications/react-router-7-framework/vite.config.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,20 @@ | ||
| import { reactRouter } from '@react-router/dev/vite'; | ||
| import { sentryReactRouter } from '@sentry/react-router/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [reactRouter()], | ||
| export default defineConfig(config => { | ||
| return { | ||
| plugins: [ | ||
| reactRouter(), | ||
| sentryReactRouter( | ||
| { | ||
| release: { name: 'react-router-7-framework-e2e' }, | ||
| sourcemaps: { disable: true }, | ||
| // The app is instrumented at runtime by `instrument.mjs`, and only uses the plugin for the release. | ||
| buildTimeInstrumentation: false, | ||
| }, | ||
| config, | ||
| ), | ||
| ], | ||
| }; | ||
| }); |
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
32 changes: 32 additions & 0 deletions
32
dev-packages/e2e-tests/test-applications/react-router-8-framework/tests/release.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { readdirSync, readFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
| import { APP_NAME, RELEASE } from './constants'; | ||
|
|
||
| test.describe('release', () => { | ||
| test('is not in the content-hashed client assets', () => { | ||
| const filesWithRelease = readdirSync(path.join(process.cwd(), 'build/client/assets'), { | ||
| recursive: true, | ||
| withFileTypes: true, | ||
| }) | ||
| .filter(entry => entry.isFile()) | ||
| .map(entry => path.join(entry.parentPath, entry.name)) | ||
| .filter(file => readFileSync(file, 'utf8').includes(RELEASE)); | ||
|
|
||
| expect(filesWithRelease).toEqual([]); | ||
| }); | ||
|
|
||
| test('reaches browser events through the page', async ({ page }) => { | ||
| const errorPromise = waitForError(APP_NAME, errorEvent => { | ||
| return errorEvent?.exception?.values?.[0]?.value === '¡Madre mía!'; | ||
| }); | ||
|
|
||
| await page.goto('/errors/client'); | ||
| await page.locator('#throw-on-click').click(); | ||
|
|
||
| const error = await errorPromise; | ||
|
|
||
| expect(error.release).toBe(RELEASE); | ||
| }); | ||
| }); |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { consoleSandbox } from '@sentry/core'; | ||
| import { RELEASE_META_TAG_NAME } from '../common/utils'; | ||
| import { injectIntoHead } from './headTagInjector'; | ||
|
|
||
| type HandleDocumentRequest = (...args: unknown[]) => unknown; | ||
|
|
||
| type ServerBuildEntry = { module: { default?: unknown } }; | ||
|
|
||
| /** | ||
| * Wraps the server build's document request handler, so every HTML document it renders carries the release in a | ||
| * meta tag. The Vite plugin calls this from the server build, after it turned off the bundler plugin's release | ||
| * injection, so the release stays out of the content-hashed client chunks. | ||
| * | ||
| * Any `handleRequest` gets the tag, including the default one and one that does not use the SDK's helpers. SPA mode | ||
| * and prerendering render their HTML through the same handler at build time. | ||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
| */ | ||
| export function injectClientRelease(entry: ServerBuildEntry | undefined, release: string): void { | ||
| const handleRequest = entry?.module?.default; | ||
| if (!entry || typeof handleRequest !== 'function') { | ||
| // The client build left the release out, so without the tag browser events have no release. | ||
| consoleSandbox(() => { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| '[Sentry] Could not find the request handler in the React Router server build, so browser events will not have a release. Pass `release` to `Sentry.init` in `entry.client`.', | ||
| ); | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const tag = `<meta name="${RELEASE_META_TAG_NAME}" content="${escapeAttribute(release)}"/>`; | ||
|
|
||
| async function sentryHandleRequestWithRelease(this: unknown, ...args: unknown[]): Promise<unknown> { | ||
| const response = await (handleRequest as HandleDocumentRequest).apply(this, args); | ||
| return addTagToDocument(response, tag); | ||
| } | ||
|
|
||
| entry.module = { ...entry.module, default: sentryHandleRequestWithRelease }; | ||
| } | ||
|
|
||
| function addTagToDocument(response: unknown, tag: string): unknown { | ||
| if (!(response instanceof Response) || !response.body || response.headers.has('content-encoding')) { | ||
| return response; | ||
| } | ||
|
|
||
| const contentType = response.headers.get('content-type'); | ||
| if (contentType && !contentType.includes('text/html')) { | ||
| return response; | ||
| } | ||
|
|
||
| const headers = new Headers(response.headers); | ||
| headers.delete('content-length'); | ||
|
|
||
| return new Response(injectIntoHead(response.body, tag), { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| headers, | ||
| }); | ||
| } | ||
|
|
||
| function escapeAttribute(value: string): string { | ||
| return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); | ||
| } | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.