Skip to content

Commit c356b37

Browse files
committed
fix(tanstackstart-react): detect tunnel route conflicts under both tsr quote styles
Made-with: Cursor
1 parent 29a5d89 commit c356b37

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ function normalizeTunnelRouteOptions(options: TunnelRouteOptions): NormalizedTun
8282
return { resolvedPath: resolveTunnelRoute(path || true), allowedDsns };
8383
}
8484

85+
// `routeTree.gen.ts` quote style follows `tsr.config.json#quoteStyle` (`single` | `double`),
86+
// so we check both forms for each route-identifying key.
87+
const ROUTE_CONFLICT_KEYS = ['fullPath', 'path', 'id'] as const;
88+
8589
function hasRouteConflict(source: string, resolvedTunnelRoute: string): boolean {
86-
return (
87-
source.includes(`fullPath: '${resolvedTunnelRoute}'`) ||
88-
source.includes(`path: '${resolvedTunnelRoute}'`) ||
89-
source.includes(`id: '${resolvedTunnelRoute}'`)
90-
);
90+
const literals = [`'${resolvedTunnelRoute}'`, `"${resolvedTunnelRoute}"`];
91+
return ROUTE_CONFLICT_KEYS.some(key => literals.some(literal => source.includes(`${key}: ${literal}`)));
9192
}
9293

9394
function injectAfterLastImport(source: string, statement: string): string {

packages/tanstackstart-react/test/vite/tunnelRoute.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ describe('tunnelRoute vite plugin', () => {
9797
);
9898
});
9999

100+
it('fails on route conflict when routeTree.gen.ts uses double quotes (tsr quoteStyle: double)', () => {
101+
const doubleQuotedMonitorTree = ROUTE_TREE_SOURCE.replace("path: '/'", 'path: "/monitor"').replace(
102+
"id: '/'",
103+
'id: "/monitor"',
104+
);
105+
106+
expect(() => injectManagedTunnelRoute(doubleQuotedMonitorTree, '/monitor')).toThrow(
107+
'Cannot register managed tunnel route "/monitor" because an existing TanStack Start route already uses that path.',
108+
);
109+
});
110+
100111
it('loads a virtual managed tunnel route module for a static tunnel path', async () => {
101112
const plugin = makeTunnelRoutePlugin({
102113
allowedDsns: ['http://public@localhost:3031/1337'],

0 commit comments

Comments
 (0)