Repository navigation
fix(solidstart): Deliver the release to the browser through the page #26513
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 1 commit into
feat/webpack-plugin-release-inject-html
from
fix/solidstart-release-runtime
Nov 18, 2026
+756
−52
Merged
Changes from all commits
Commits
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
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
15 changes: 15 additions & 0 deletions
15
dev-packages/e2e-tests/test-applications/solidstart-2/tests/release.client.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,15 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('sends the release that the server adds to the page with client events', async ({ page }) => { | ||
| const errorPromise = waitForError('solidstart-2', async errorEvent => { | ||
| return errorEvent?.exception?.values?.[0]?.value === 'Uncaught error thrown from Solid Start E2E test app'; | ||
| }); | ||
|
|
||
| await page.goto('/client-error'); | ||
| await expect(page.locator('meta[name="sentry-release"]')).toHaveAttribute('content', 'test-release'); | ||
| await page.locator('#errorBtn').click(); | ||
| const error = await errorPromise; | ||
|
|
||
| expect(error.release).toBe('test-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
17 changes: 17 additions & 0 deletions
17
dev-packages/e2e-tests/test-applications/solidstart-spa/tests/release.client.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,17 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('sends the release from the prerendered page with client events', async ({ page }) => { | ||
| const errorPromise = waitForError('solidstart-spa', async errorEvent => { | ||
| return errorEvent?.exception?.values?.[0]?.value === 'Uncaught error thrown from Solid Start E2E test app'; | ||
| }); | ||
|
|
||
| // `/` is the page SPA mode prerenders. | ||
| await page.goto('/'); | ||
| await expect(page.locator('meta[name="sentry-release"]')).toHaveAttribute('content', 'test-release'); | ||
| await page.getByRole('link', { name: 'Client error' }).click(); | ||
| await page.locator('#errorBtn').click(); | ||
| const error = await errorPromise; | ||
|
|
||
| expect(error.release).toBe('test-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
15 changes: 15 additions & 0 deletions
15
dev-packages/e2e-tests/test-applications/solidstart/tests/release.client.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,15 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('sends the release that the server adds to the page with client events', async ({ page }) => { | ||
| const errorPromise = waitForError('solidstart', async errorEvent => { | ||
| return errorEvent?.exception?.values?.[0]?.value === 'Uncaught error thrown from Solid Start E2E test app'; | ||
| }); | ||
|
|
||
| await page.goto('/client-error'); | ||
| await expect(page.locator('meta[name="sentry-release"]')).toHaveAttribute('content', 'test-release'); | ||
| await page.locator('#errorBtn').click(); | ||
| const error = await errorPromise; | ||
|
|
||
| expect(error.release).toBe('test-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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** Name of the `<meta>` tag through which the server hands the release to the browser SDK. */ | ||
| export const RELEASE_META_TAG_NAME = 'sentry-release'; | ||
|
|
||
| /** Set by the server bundle's banner on SolidStart 1, read by the Nitro plugin that adds the `<meta>` tag. */ | ||
| export const RELEASE_GLOBAL = '__sentry_solidstart_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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { RELEASE_META_TAG_NAME } from '../common/release'; | ||
|
|
||
| const HEAD_OPENING_TAG = /<head(?:\s[^>]*)?>/i; | ||
|
|
||
| // Bounds what a streamed page is buffered for while looking for `<head>`. | ||
| const MAX_BUFFERED_CHARS = 64 * 1024; | ||
|
|
||
| /** | ||
| * Adds the release `<meta>` tag that the browser SDK reads to an HTML page. Bodies that are not HTML, or whose | ||
| * `<head>` cannot be found, are returned as they are. | ||
| * | ||
| * @param contentType The response's content type. A `Response` body brings its own. | ||
| */ | ||
| export function addReleaseMetaTag(body: unknown, release: string, contentType: string | undefined): unknown { | ||
| if (body instanceof Response) { | ||
| return addReleaseMetaTagToResponse(body, release); | ||
| } | ||
|
|
||
| if (!isHtml(contentType)) { | ||
| return body; | ||
| } | ||
|
|
||
| if (typeof body === 'string') { | ||
| return injectIntoHtml(body, release) ?? body; | ||
| } | ||
|
|
||
| if (body instanceof ReadableStream) { | ||
| return injectIntoHtmlStream(body, release); | ||
| } | ||
|
|
||
| return body; | ||
| } | ||
|
|
||
| function addReleaseMetaTagToResponse(response: Response, release: string): Response { | ||
| if (!response.body || response.headers.has('content-encoding') || !isHtml(response.headers.get('content-type'))) { | ||
| return response; | ||
| } | ||
|
|
||
| const headers = new Headers(response.headers); | ||
| headers.delete('content-length'); | ||
|
|
||
| return new Response(injectIntoHtmlStream(response.body, release), { | ||
| status: response.status, | ||
| statusText: response.statusText, | ||
| headers, | ||
| }); | ||
| } | ||
|
|
||
| function isHtml(contentType: string | null | undefined): boolean { | ||
| return !!contentType?.toLowerCase().startsWith('text/html'); | ||
| } | ||
|
|
||
| function injectIntoHtml(html: string, release: string): string | undefined { | ||
| const match = HEAD_OPENING_TAG.exec(html); | ||
| if (!match) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const end = match.index + match[0].length; | ||
| return `${html.slice(0, end)}<meta name="${RELEASE_META_TAG_NAME}" content="${escapeAttribute(release)}">${html.slice(end)}`; | ||
| } | ||
|
|
||
| function injectIntoHtmlStream(body: ReadableStream<Uint8Array | string>, release: string): ReadableStream<Uint8Array> { | ||
| const decoder = new TextDecoder(); | ||
| const encoder = new TextEncoder(); | ||
| let pending: string | undefined = ''; | ||
|
|
||
| const decode = (chunk: Uint8Array | string): string => | ||
| typeof chunk === 'string' ? chunk : decoder.decode(chunk, { stream: true }); | ||
|
|
||
| return body.pipeThrough( | ||
| new TransformStream<Uint8Array | string, Uint8Array>({ | ||
| transform(chunk, controller) { | ||
| if (pending === undefined) { | ||
| controller.enqueue(encoder.encode(decode(chunk))); | ||
| return; | ||
| } | ||
|
|
||
| pending += decode(chunk); | ||
| const injected = injectIntoHtml(pending, release); | ||
| if (injected !== undefined || pending.length > MAX_BUFFERED_CHARS) { | ||
| controller.enqueue(encoder.encode(injected ?? pending)); | ||
| pending = undefined; | ||
| } | ||
| }, | ||
| flush(controller) { | ||
| const rest = (pending ?? '') + decoder.decode(); | ||
| if (rest) { | ||
| controller.enqueue(encoder.encode(rest)); | ||
| } | ||
| }, | ||
| }), | ||
| ); | ||
| } | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { addReleaseMetaTag } from './releaseMetaTag'; | ||
|
|
||
| declare const __SENTRY_SOLIDSTART_RELEASE__: string | undefined; | ||
|
|
||
| /** | ||
| * Hands the release to the browser SDK through a `<meta>` tag in each page on SolidStart 2 (Nitro v3), so it stays | ||
| * out of the content-hashed client chunks. `sentrySolidStart` registers it as a Nitro middleware and defines the | ||
| * release for the server environments. | ||
| */ | ||
| export default async function sentryReleaseMiddleware(_event: unknown, next: () => unknown): Promise<unknown> { | ||
| const response = await next(); | ||
| const release = typeof __SENTRY_SOLIDSTART_RELEASE__ !== 'undefined' ? __SENTRY_SOLIDSTART_RELEASE__ : undefined; | ||
|
|
||
| return release && response instanceof Response ? addReleaseMetaTag(response, release, undefined) : response; | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
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,29 @@ | ||
| import { GLOBAL_OBJ } from '@sentry/core'; | ||
| import type { NitroAppPlugin } from 'nitropack'; | ||
| import { RELEASE_GLOBAL } from '../common/release'; | ||
| import { addReleaseMetaTag } from './releaseMetaTag'; | ||
|
|
||
| /** | ||
| * Hands the release to the browser SDK through a `<meta>` tag in each page on SolidStart v1 (Nitro v2), so it stays | ||
| * out of the content-hashed client chunks. `withSentry` registers it. | ||
| */ | ||
| export default (nitroApp => { | ||
| nitroApp.hooks.hook('beforeResponse', (event, response) => { | ||
| // The server bundle's banner sets the global. | ||
| const release = (GLOBAL_OBJ as { [RELEASE_GLOBAL]?: string })[RELEASE_GLOBAL]; | ||
| if (!release) { | ||
| return; | ||
| } | ||
|
|
||
| const contentType = event.node.res.getHeader('content-type'); | ||
| const body = addReleaseMetaTag( | ||
| response.body, | ||
| release, | ||
| Array.isArray(contentType) ? contentType[0] : contentType?.toString(), | ||
| ); | ||
| if (body !== response.body) { | ||
| event.node.res.removeHeader('content-length'); | ||
| response.body = body; | ||
| } | ||
| }); | ||
| }) satisfies NitroAppPlugin; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HTML rewrite can crash Workers
Medium Severity
injectIntoHtmlStreamusespipeThroughwith a customTransformStream. Workerd only supports custom transformers from compatibility date 2024-11-11, and this runs on every HTML response with no try/catch. On SolidStart Cloudflare (or older MiniOxygen-style runtimes) constructing that transformer throws and fails the page. The React Router SDK in this repo avoidedTransformStreamfor that reason.Additional Locations (1)
packages/solidstart/src/nitro/releaseMiddleware.ts#L9-L15Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 523a186. Configure here.