GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(remix): Deliver the release through the rendered page instead of client chunks by sentry-junior[bot] · Pull Request #26507 · getsentry/sentry-javascript

fix(remix): Deliver the release through the rendered page instead of client chunks #26507

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.

Sign up for GitHub

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 2 commits into fix/astro-release-runtime from fix/remix-release-runtime
Nov 18, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(remix): Deliver the release through the rendered page instead of client chunks #26507

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
f4b89d4
fix(remix): Deliver the release through the rendered page instead of …
sentry-junior[bot] Nov 17, 2026
3fa4835
fixup! fix(remix): Deliver the release through the rendered page inst…
isaacs Nov 18, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

35 changes: 35 additions & 0 deletions 35 dev-packages/e2e-tests/test-applications/create-remix-app-express/tests/release.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect, test } from '@playwright/test';
import { waitForError } from '@sentry-internal/test-utils';
import * as fs from 'fs';
import * as path from 'path';

const RELEASE = 'create-remix-app-express-release';

// The release only reaches the page through the production build.
test.skip(process.env.TEST_ENV === 'development', 'Needs the production build');

function listFiles(dir: string): string[] {
return fs
.readdirSync(dir, { withFileTypes: true })
.flatMap(entry => (entry.isDirectory() ? listFiles(path.join(dir, entry.name)) : [path.join(dir, entry.name)]));
}

test('Sends the release with client-side errors', async ({ page }) => {
const errorPromise = waitForError('create-remix-app-express', errorEvent => {
return errorEvent.exception?.values?.[0].value === 'I am an error!';
});

await page.goto('/');
await page.locator('id=exception-button').click();

const errorEvent = await errorPromise;

expect(errorEvent.release).toBe(RELEASE);
});

// A release in the content-hashed client chunks renames them on every release.
test('Keeps the release out of the client build', () => {
const filesWithRelease = listFiles('build/client').filter(file => fs.readFileSync(file, 'utf-8').includes(RELEASE));

expect(filesWithRelease).toEqual([]);
});
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

4 changes: 3 additions & 1 deletion 4 dev-packages/e2e-tests/test-applications/create-remix-app-express/vite.config.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ installGlobals();
export default defineConfig({
plugins: [
remix(),
sentryRemixVitePlugin(),
sentryRemixVitePlugin({
release: { name: 'create-remix-app-express-release', create: false },
}),
tsconfigPaths({
// The dev server config errors are not relevant to this test app
// https://github.com/aleclarson/vite-tsconfig-paths?tab=readme-ov-file#options
Expand Down
14 changes: 13 additions & 1 deletion 14 packages/remix/src/client/sdk.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Client } from '@sentry/core';
import { applySdkMetadata } from '@sentry/core';
import { applySdkMetadata, GLOBAL_OBJ } from '@sentry/core';
import { init as reactInit } from '@sentry/react';
import type { RemixOptions } from '../utils/remixOptions';
import { createRemixRouteProvider } from './routeProvider';
Expand All @@ -10,15 +10,27 @@ import { createRemixRouteProvider } from './routeProvider';
* @returns The initialized SDK.
*/
export function init(options: RemixOptions): Client | undefined {
const release = options.release ?? getReleaseFromRemixContext();
const opts = {
// The manifest is injected at build time, so route parameterization works from `init` on, even with
// tracing disabled.
routeProvider: createRemixRouteProvider(),
...options,
// Left unset when unknown, so the browser SDK still falls back to an injected `SENTRY_RELEASE`.
...(release !== undefined && { release }),
environment: options.environment || process.env.NODE_ENV,
};

applySdkMetadata(opts, 'remix', ['remix', 'react']);

return reactInit(opts);
}

/**
* The Vite plugin adds the release to `window.__remixContext` on the server, so it stays out of the
* content-hashed client chunks.
*/
function getReleaseFromRemixContext(): string | undefined {
const release = (GLOBAL_OBJ as { __remixContext?: { sentryRelease?: unknown } }).__remixContext?.sentryRelease;
return typeof release === 'string' ? release : undefined;
}
13 changes: 10 additions & 3 deletions 13 packages/remix/src/vite/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Plugin } from 'vite';
import { makeOrchestrionPlugin } from './orchestrionPlugin';
import { makeReleasePlugin } from './releasePlugin';
import { makeRouteManifestPlugin } from './routeManifestPlugin';
import { makeAddSentryVitePlugin, makeEnableSourceMapsPlugin } from './sourceMaps';
import type { SentryRemixVitePluginOptions } from './types';
Expand All @@ -11,8 +12,9 @@ export type { SentryRemixVitePluginOptions };
*
* Add these to your Vite configuration to
* - inject the Remix route manifest, so client-side transactions are parameterized,
* - build-time instrument supported server-side dependencies (such as database clients), and
* - inject debug IDs and upload source maps to Sentry.
* - build-time instrument supported server-side dependencies (such as database clients),
* - inject debug IDs and upload source maps to Sentry, and
* - pass the release to the browser SDK through the rendered page instead of the client chunks.
*
* @example
* ```typescript
Expand Down Expand Up @@ -48,7 +50,12 @@ export function sentryRemixVitePlugin(options: SentryRemixVitePluginOptions = {}
//
// Order matters: Vite passes the already-merged config to every `config` hook, so the deletion
// plugin has to read `build.sourcemap` before `makeEnableSourceMapsPlugin` sets it to 'hidden'.
plugins.push(...makeAddSentryVitePlugin(options));
if (options.release?.inject !== false) {
plugins.push(...makeAddSentryVitePlugin({ ...options, release: { ...options.release, inject: false } }));
plugins.push(makeReleasePlugin(options));
} else {
plugins.push(...makeAddSentryVitePlugin(options));
}

// `'disable-upload'` still generates them - debug IDs are injected and the user uploads by hand.
if (options.sourcemaps?.disable !== true) {
Expand Down
91 changes: 91 additions & 0 deletions 91 packages/remix/src/vite/releasePlugin.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { generateReleaseInjectorCode, resolveReleaseName } from '@sentry/bundler-plugins/core';
import { stringifyForCodeInjection } from '@sentry/core';
import type { Plugin } from 'vite';
import type { SentryRemixVitePluginOptions } from './types';

const SERVER_BUILD_ID = '\0virtual:remix/server-build';
const SERVER_BUILD_ENTRY_EXPORT = /export const entry\s*=\s*\{/;
const RELEASE_MODULE_ID = 'virtual:sentry-remix-release';
const RESOLVED_RELEASE_MODULE_ID = `\0${RELEASE_MODULE_ID}`;

/**
* Delivers the release to the browser SDK through the HTML document, so it never ends up in a
* content-hashed client chunk. A release in the client chunks changes their hashes on every release.
*
* Wraps `entry.server`'s default export in the Remix server build to add the release to
* `window.__remixContext`, which `<Scripts />` already renders. The server build also sets
* `SENTRY_RELEASE` itself, because the bundler plugin no longer injects it into any chunk.
*/
export function makeReleasePlugin(options: SentryRemixVitePluginOptions): Plugin {
let release: string | undefined;
let isSsrBuild = false;
let transformedServerBuild = false;

return {
name: 'sentry-remix-release',
apply: 'build',

configResolved(config) {
isSsrBuild = !!config.build.ssr;
// Resolved here rather than up front: the bundler plugin loads `.env.sentry-build-plugin`,
// which can set `SENTRY_RELEASE`, when it is created.
release = resolveReleaseName(options.release?.name);
},

resolveId(id) {
return id === RELEASE_MODULE_ID ? RESOLVED_RELEASE_MODULE_ID : null;
},

load(id) {
return id === RESOLVED_RELEASE_MODULE_ID && release ? getReleaseModuleCode(release) : null;
},

transform(code, id) {
if (id !== SERVER_BUILD_ID || !release || !SERVER_BUILD_ENTRY_EXPORT.test(code)) {
return null;
}

transformedServerBuild = true;

// The import comes first so `SENTRY_RELEASE` is set before `entry.server` and the routes are
// evaluated, and it shares the first line so the module's line numbers stay the same.
return {
code: `import { wrapHandleRequest as __sentryWrapHandleRequest } from ${JSON.stringify(RELEASE_MODULE_ID)};${code}
entry.module = { ...entry.module, default: __sentryWrapHandleRequest(entry.module.default) };
`,
map: null,
};
},

buildEnd() {
if (isSsrBuild && release && !transformedServerBuild) {
this.warn(
`Could not find the Remix server build, so the release "${release}" does not reach the browser SDK. Pass \`release\` to \`Sentry.init\` in your client entry.`,
);
}
},
};
}

/**
* Only exported for testing.
*/
export function getReleaseModuleCode(release: string): string {
const handoffField = `"sentryRelease":${stringifyForCodeInjection(release)}`;

return `${generateReleaseInjectorCode({ release, injectBuildInformation: false }).code()}
const handoffField = ${stringifyForCodeInjection(handoffField)};
export function wrapHandleRequest(handleRequest) {
if (typeof handleRequest !== 'function') {
return handleRequest;
}
return function (request, statusCode, headers, context) {
const handoff = context && context.serverHandoffString;
if (typeof handoff === 'string' && handoff.charAt(0) === '{') {
context.serverHandoffString = '{' + handoffField + (handoff === '{}' ? '}' : ',' + handoff.slice(1));
}
return handleRequest.apply(this, arguments);
};
}
`;
}
31 changes: 31 additions & 0 deletions 31 packages/remix/test/index.client.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ describe('Client init()', () => {
expect(reactInit).toHaveBeenLastCalledWith(expect.objectContaining({ routeProvider }));
});

describe('release', () => {
afterEach(() => {
delete (globalThis as { __remixContext?: unknown }).__remixContext;
});

it('reads the release the server build added to the Remix context', () => {
(globalThis as { __remixContext?: unknown }).__remixContext = { sentryRelease: 'page-release' };

init({});

expect(reactInit).toHaveBeenLastCalledWith(expect.objectContaining({ release: 'page-release' }));
});

it('prefers an explicit release', () => {
(globalThis as { __remixContext?: unknown }).__remixContext = { sentryRelease: 'page-release' };

init({ release: 'explicit-release' });

expect(reactInit).toHaveBeenLastCalledWith(expect.objectContaining({ release: 'explicit-release' }));
});

// An explicit `release: undefined` would override the browser SDK's `SENTRY_RELEASE` fallback.
it('sets no release when the Remix context has none', () => {
(globalThis as { __remixContext?: unknown }).__remixContext = {};

init({});

expect(reactInit.mock.lastCall?.[0]).not.toHaveProperty('release');
});
});

it('returns client from init', () => {
expect(init({})).not.toBeUndefined();
});
Expand Down
18 changes: 18 additions & 0 deletions 18 packages/remix/test/vite/index.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ vi.mock('@sentry/server-utils/orchestrion/vite', () => ({
type CapturedSentryOptions = {
applicationKey?: string;
bundleSizeOptimizations?: { excludeTracing?: boolean };
release?: { name?: string; inject?: boolean };
sourcemaps?: { filesToDeleteAfterUpload?: Promise<unknown> };
};

Expand All @@ -46,6 +47,7 @@ vi.mock('@sentry/bundler-plugins/vite', () => ({
const SOURCE_MAP_PLUGINS = [
'sentry-remix-files-to-delete-after-upload',
'sentry-vite-plugin',
'sentry-remix-release',
'sentry-remix-update-source-map-setting',
];

Expand Down Expand Up @@ -129,9 +131,25 @@ describe('sentryRemixVitePlugin', () => {
'code-transformer',
'sentry-remix-files-to-delete-after-upload',
'sentry-vite-plugin',
'sentry-remix-release',
]);
});

// A release in the client chunks changes their content hash on every release.
it('turns off release injection and delivers the release through the rendered page', () => {
const plugins = sentryRemixVitePlugin({ release: { name: 'my-release' } });

expect(capturedSentryOptions?.release).toEqual({ name: 'my-release', inject: false });
expect(plugins.map(plugin => plugin.name)).toContain('sentry-remix-release');
});

it('delivers nothing at runtime when the user turned off release injection', () => {
const plugins = sentryRemixVitePlugin({ release: { name: 'my-release', inject: false } });

expect(capturedSentryOptions?.release).toEqual({ name: 'my-release', inject: false });
expect(plugins.map(plugin => plugin.name)).not.toContain('sentry-remix-release');
});

it('forwards the non-source-map options when source maps are disabled', () => {
sentryRemixVitePlugin({
sourcemaps: { disable: true },
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.