Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export function makeAutoInstrumentMiddlewarePlugin(options: AutoInstrumentMiddle
return null;
}

// Skip if not a TS/JS file
if (!/\.(ts|tsx|js|jsx|mjs|mts)$/.test(id)) {
// Skip if not a TS/JS file. The id can end in a query, e.g. the server function module `foo.tsx?tss-serverfn-split`.
if (!/\.(ts|tsx|js|jsx|mjs|mts)$/.test(id.split('?')[0] ?? id)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ createStart(() => ({ requestMiddleware: wrapMiddlewaresWithSentry({ myMiddleware
expect(result!.code).toContain("import { wrapMiddlewaresWithSentry } from '@sentry/tanstackstart-react'");
});

it('instruments server function middlewares in a module whose id ends in a query', () => {
const plugin = makeAutoInstrumentMiddlewarePlugin() as PluginWithTransform;
const code = `
import { createServerFn } from '@tanstack/react-start';
const serverFn = createServerFn().middleware([authMiddleware]).handler(async () => ({}));
`;
const result = plugin.transform(code, '/app/routes/foo.tsx?tss-serverfn-split');

expect(result).not.toBeNull();
expect(result!.code).toContain('.middleware(wrapMiddlewaresWithSentry({ authMiddleware }))');
});

it('does not instrument non-TS/JS files whose id ends in a query', () => {
const plugin = makeAutoInstrumentMiddlewarePlugin() as PluginWithTransform;
const result = plugin.transform(createStartFile, '/app/start.css?direct');

expect(result).toBeNull();
});

it('instruments both start files and route files', () => {
const plugin = makeAutoInstrumentMiddlewarePlugin() as PluginWithTransform;

Expand Down
Loading