Skip to content

Commit d92f1dc

Browse files
committed
fix(tanstackstart-react): Add workerd and worker export conditions
Add `workerd` and `worker` export conditions to the `.` entry in package.json, pointing to `index.server.js`. This prevents the Cloudflare Vite plugin's resolve conditions (`workerd`, `worker`, `module`, `browser`) from falling through to the `browser` condition, which would resolve to `index.client.js` and trigger TanStack Start's import-protection plugin rejecting `*.client.*` files in the server environment. Users deploying to Cloudflare Workers will need `nodejs_compat` enabled in their wrangler configuration. A dedicated Cloudflare entrypoint (without `@sentry/node` dependency) will be addressed in a follow-up PR.
1 parent 801e41a commit d92f1dc

File tree

11 files changed

+41
-94
lines changed

11 files changed

+41
-94
lines changed

packages/tanstackstart-react/package.json

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
".": {
2121
"types": "./build/types/index.types.d.ts",
2222
"workerd": {
23-
"import": "./build/esm/cloudflare/index.js",
24-
"require": "./build/cjs/cloudflare/index.js"
23+
"import": "./build/esm/index.server.js",
24+
"require": "./build/cjs/index.server.js"
2525
},
2626
"worker": {
27-
"import": "./build/esm/cloudflare/index.js",
28-
"require": "./build/cjs/cloudflare/index.js"
27+
"import": "./build/esm/index.server.js",
28+
"require": "./build/cjs/index.server.js"
2929
},
3030
"browser": {
3131
"import": "./build/esm/index.client.js",
@@ -36,12 +36,6 @@
3636
"require": "./build/cjs/index.server.js"
3737
}
3838
},
39-
"./cloudflare": {
40-
"types": "./build/types/cloudflare/index.d.ts",
41-
"import": "./build/esm/cloudflare/index.js",
42-
"require": "./build/cjs/cloudflare/index.js",
43-
"default": "./build/esm/cloudflare/index.js"
44-
},
4539
"./import": {
4640
"import": {
4741
"default": "./build/import-hook.mjs"
@@ -51,11 +45,6 @@
5145
"import": {
5246
"default": "./build/loader-hook.mjs"
5347
}
54-
},
55-
"./vite": {
56-
"types": "./build/types/vite/index.d.ts",
57-
"import": "./build/esm/vite/index.js",
58-
"require": "./build/cjs/vite/index.js"
5948
}
6049
},
6150
"typesVersions": {
@@ -75,7 +64,7 @@
7564
"@sentry/core": "10.39.0",
7665
"@sentry/node": "10.39.0",
7766
"@sentry/react": "10.39.0",
78-
"@sentry/vite-plugin": "^5.1.0"
67+
"@sentry/vite-plugin": "^4.8.0"
7968
},
8069
"devDependencies": {
8170
"vite": "^5.4.11"
@@ -91,7 +80,7 @@
9180
"build:dev:watch": "yarn build:watch",
9281
"build:transpile:watch": "nodemon --ext ts --watch src scripts/buildRollup.ts",
9382
"build:tarball": "npm pack",
94-
"circularDepCheck": "madge --circular src/index.client.ts && madge --circular src/index.server.ts && madge --circular src/index.types.ts && madge --circular src/cloudflare/index.ts",
83+
"circularDepCheck": "madge --circular src/index.client.ts && madge --circular src/index.server.ts && madge --circular src/index.types.ts",
9584
"clean": "rimraf build coverage sentry-tanstackstart-react-*.tgz",
9685
"fix": "eslint . --format stylish --fix",
9786
"lint": "eslint . --format stylish",

packages/tanstackstart-react/rollup.npm.config.mjs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ import { makeBaseNPMConfig, makeNPMConfigVariants, makeOtelLoaders } from '@sent
33
export default [
44
...makeNPMConfigVariants(
55
makeBaseNPMConfig({
6-
entrypoints: [
7-
'src/index.server.ts',
8-
'src/index.client.ts',
9-
'src/client/index.ts',
10-
'src/server/index.ts',
11-
'src/vite/index.ts',
12-
'src/cloudflare/index.ts',
13-
],
6+
entrypoints: ['src/index.server.ts', 'src/index.client.ts', 'src/client/index.ts', 'src/server/index.ts'],
147
}),
158
),
169
...makeOtelLoaders('./build', 'sentry-node'),

packages/tanstackstart-react/src/cloudflare/index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/tanstackstart-react/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
export * from './config';
44
export * from './server';
55
export * from './common';
6+
export * from './vite';

packages/tanstackstart-react/src/index.types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from './config';
1212
export * from './client';
1313
export * from './server';
1414
export * from './common';
15+
export * from './vite';
1516

1617
/** Initializes Sentry TanStack Start SDK */
1718
export declare function init(options: Options | clientSdk.BrowserOptions | serverSdk.NodeOptions): Client | undefined;
@@ -22,6 +23,9 @@ export declare const contextLinesIntegration: typeof clientSdk.contextLinesInteg
2223
export declare const getDefaultIntegrations: (options: Options) => Integration[];
2324
export declare const defaultStackParser: StackParser;
2425

26+
export declare const ErrorBoundary: typeof clientSdk.ErrorBoundary;
27+
export declare const withErrorBoundary: typeof clientSdk.withErrorBoundary;
28+
2529
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
2630

2731
export declare const growthbookIntegration: typeof clientSdk.growthbookIntegration;
@@ -34,6 +38,5 @@ export declare const unleashIntegration: typeof clientSdk.unleashIntegration;
3438

3539
export declare const wrapMiddlewaresWithSentry: typeof serverSdk.wrapMiddlewaresWithSentry;
3640

37-
export declare const tanstackRouterBrowserTracingIntegration: typeof clientSdk.tanstackRouterBrowserTracingIntegration;
3841
export declare const sentryGlobalRequestMiddleware: typeof serverSdk.sentryGlobalRequestMiddleware;
3942
export declare const sentryGlobalFunctionMiddleware: typeof serverSdk.sentryGlobalFunctionMiddleware;
Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// import/export got a false positive, and affects most of our index barrel files
22
// can be removed once following issue is fixed: https://github.com/import-js/eslint-plugin-import/issues/703
33
/* eslint-disable import/export */
4-
import type { Integration } from '@sentry/core';
5-
64
export * from '@sentry/node';
75

86
export { init } from './sdk';
@@ -11,15 +9,28 @@ export { wrapMiddlewaresWithSentry } from './middleware';
119
export { sentryGlobalRequestMiddleware, sentryGlobalFunctionMiddleware } from './globalMiddleware';
1210

1311
/**
14-
* A no-op stub of the browser tracing integration for the server. Router setup code is shared between client and server,
15-
* so this stub is needed to prevent build errors during SSR bundling.
12+
* A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
13+
* so they should simply be a passthrough.
14+
*/
15+
export const ErrorBoundary = (props: React.PropsWithChildren<unknown>): React.ReactNode => {
16+
if (!props.children) {
17+
return null;
18+
}
19+
20+
if (typeof props.children === 'function') {
21+
return (props.children as () => React.ReactNode)();
22+
}
23+
24+
return props.children;
25+
};
26+
27+
/**
28+
* A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch
29+
* SSR errors so they should simply be a passthrough.
1630
*/
17-
export function tanstackRouterBrowserTracingIntegration(
18-
_router: unknown,
19-
_options?: Record<string, unknown>,
20-
): Integration {
21-
return {
22-
name: 'BrowserTracing',
23-
setup() {},
24-
};
31+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32+
export function withErrorBoundary<P extends Record<string, any>>(
33+
WrappedComponent: React.ComponentType<P>,
34+
): React.FC<P> {
35+
return WrappedComponent as React.FC<P>;
2536
}

packages/tanstackstart-react/src/server/middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { Span } from '@sentry/core';
2-
import { addNonEnumerableProperty, getActiveSpan, startSpanManual, withActiveSpan } from '@sentry/core';
1+
import { addNonEnumerableProperty } from '@sentry/core';
2+
import type { Span } from '@sentry/node';
3+
import { getActiveSpan, startSpanManual, withActiveSpan } from '@sentry/node';
34
import type { MiddlewareWrapperOptions, TanStackMiddlewareBase } from '../common/types';
45
import { getMiddlewareSpanOptions } from './utils';
56

packages/tanstackstart-react/src/server/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { StartSpanOptions } from '@sentry/core';
2-
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/node';
33

44
/**
55
* Extracts the SHA-256 hash from a server function pathname.

packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/core';
1+
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/node';
22
import { extractServerFunctionSha256 } from './utils';
33

44
export type ServerEntry = {

packages/tanstackstart-react/src/vite/sentryTanstackStart.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface SentryTanstackStartOptions extends BuildTimeOptionsBase {
2828
* ```typescript
2929
* // vite.config.ts
3030
* import { defineConfig } from 'vite';
31-
* import { sentryTanstackStart } from '@sentry/tanstackstart-react/vite';
31+
* import { sentryTanstackStart } from '@sentry/tanstackstart-react';
3232
* import { tanstackStart } from '@tanstack/react-start/plugin/vite';
3333
*
3434
* export default defineConfig({

0 commit comments

Comments
 (0)