diff --git a/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/package.json b/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/package.json index 5cf6accf0cd1..688094b3d237 100644 --- a/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/package.json +++ b/dev-packages/e2e-tests/test-applications/tanstackstart-react-cloudflare/package.json @@ -28,10 +28,10 @@ "@sentry-internal/test-utils": "link:../../../test-utils", "@types/react": "^19.2.0", "@types/react-dom": "^19.2.0", - "@vitejs/plugin-react": "^4.5.0", + "@vitejs/plugin-react": "^6.1.2", "typescript": "^5.9.0", - "vite": "7.3.2", - "vite-tsconfig-paths": "^5.1.4", + "vite": "8.3.4", + "vite-tsconfig-paths": "^6.1.1", "wrangler": "^4.68.1" }, "volta": { diff --git a/dev-packages/e2e-tests/test-applications/tanstackstart-react/package.json b/dev-packages/e2e-tests/test-applications/tanstackstart-react/package.json index 89dad11c3985..410f41baecbc 100644 --- a/dev-packages/e2e-tests/test-applications/tanstackstart-react/package.json +++ b/dev-packages/e2e-tests/test-applications/tanstackstart-react/package.json @@ -14,7 +14,7 @@ "test:build:tunnel-static": "pnpm install && E2E_TEST_TUNNEL_ROUTE_MODE=static E2E_TEST_DSN=http://public@localhost:3031/1337 pnpm build", "test:build:tunnel-custom": "pnpm install && E2E_TEST_CUSTOM_TUNNEL_ROUTE=1 pnpm build", "test:build:tunnel-object": "pnpm install && E2E_TEST_TUNNEL_ROUTE_MODE=object E2E_TEST_DSN=http://public@localhost:3031/1337 pnpm build", - "test:build-latest": "pnpm add @tanstack/react-start@latest @tanstack/react-router@latest && pnpm install && pnpm build", + "test:build-latest": "pnpm add @tanstack/react-start@latest @tanstack/react-router@latest nitro@latest vite@latest @vitejs/plugin-react-swc@latest vite-tsconfig-paths@latest && pnpm install && pnpm build", "test:assert:proxy": "pnpm test && TEST_ENV=development pnpm playwright test db-drivers", "test:assert": "pnpm test:assert:proxy", "test:assert:tunnel-generated": "E2E_TEST_TUNNEL_ROUTE_MODE=dynamic E2E_TEST_DSN=http://public@localhost:3031/1337 pnpm test", diff --git a/packages/tanstackstart-react/src/vite/routePatterns.ts b/packages/tanstackstart-react/src/vite/routePatterns.ts index 5ffbdaa83c52..82a187d08e70 100644 --- a/packages/tanstackstart-react/src/vite/routePatterns.ts +++ b/packages/tanstackstart-react/src/vite/routePatterns.ts @@ -19,6 +19,16 @@ export function makeRoutePatternPlugin(): Plugin { name: 'sentry-tanstackstart-route-patterns', enforce: 'post', + // The transform below must see the SDK's own `wrapFetchWithSentry` file. Vite externalizes dependencies in + // server builds, and Nitro 3 copies external dependencies into its output instead of bundling them. + configEnvironment(name, config, env) { + if (env.command === 'serve' || (config.consumer ?? (name === 'client' ? 'client' : 'server')) !== 'server') { + return null; + } + + return { resolve: { noExternal: ['@sentry/tanstackstart-react'] } }; + }, + configResolved(config) { resolvedRoot = config.root || process.cwd(); }, diff --git a/packages/tanstackstart-react/test/vite/routePatterns.test.ts b/packages/tanstackstart-react/test/vite/routePatterns.test.ts index 413b29adafe1..abc5c92527d9 100644 --- a/packages/tanstackstart-react/test/vite/routePatterns.test.ts +++ b/packages/tanstackstart-react/test/vite/routePatterns.test.ts @@ -2,7 +2,30 @@ import * as fs from 'node:fs'; import * as os from 'node:os'; import * as path from 'node:path'; import { afterEach, beforeEach, describe, expect, it } from 'vitest'; -import { extractRoutePatterns, findRouteTreeFile } from '../../src/vite/routePatterns'; +import { extractRoutePatterns, findRouteTreeFile, makeRoutePatternPlugin } from '../../src/vite/routePatterns'; + +describe('makeRoutePatternPlugin', () => { + const configEnvironment = makeRoutePatternPlugin().configEnvironment as ( + name: string, + config: { consumer?: 'client' | 'server' }, + env: { command: 'build' | 'serve'; mode: string }, + ) => { resolve: { noExternal: string[] } } | null; + + it('bundles the SDK into server environments of a build', () => { + const build = { command: 'build', mode: 'production' } as const; + + expect(configEnvironment('ssr', {}, build)).toEqual({ resolve: { noExternal: ['@sentry/tanstackstart-react'] } }); + expect(configEnvironment('nitro', { consumer: 'server' }, build)).toEqual({ + resolve: { noExternal: ['@sentry/tanstackstart-react'] }, + }); + }); + + it('does not change client environments or the dev server', () => { + expect(configEnvironment('client', {}, { command: 'build', mode: 'production' })).toBeNull(); + expect(configEnvironment('ssr', { consumer: 'client' }, { command: 'build', mode: 'production' })).toBeNull(); + expect(configEnvironment('ssr', {}, { command: 'serve', mode: 'development' })).toBeNull(); + }); +}); describe('extractRoutePatterns', () => { it('extracts full path patterns from single-line fullPaths union', () => {