@@ -17,21 +17,39 @@ function requestLoggingPlugin(): Plugin {
1717 : existingRequestId || `ssr-${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 10 ) } ` ;
1818 const requestStart = Date . now ( ) ;
1919
20- const pathname = req . url ?. split ( '?' ) [ 0 ] || '/' ;
20+ const fullUrl = req . url || '/' ;
21+ const pathname = fullUrl . split ( '?' ) [ 0 ] ;
2122 const method = req . method || 'GET' ;
2223
23- // Extract user ID and org ID and log request initialization
24- const { userId, orgId } = await extractUserInfoFromRequest ( req ) ;
25- logRequestInit ( method , pathname , requestId , userId , orgId ) ;
24+ // Skip logging for TanStack Router component split requests and Vite internal requests
25+ // Check full URL for query params, pathname for path patterns
26+ const isTanStackSplitRequest = fullUrl . includes ( 'tsr-split=component' ) || pathname . startsWith ( '/src/routes/' ) ;
27+ const isViteInternal = pathname . startsWith ( '/@' ) || pathname . startsWith ( '/node_modules/' ) || pathname . startsWith ( '/@fs/' ) ;
28+
29+ if ( ! isTanStackSplitRequest && ! isViteInternal ) {
30+ // Extract user ID and org ID and log request initialization
31+ try {
32+ const { userId, orgId } = await extractUserInfoFromRequest ( req ) ;
33+ logRequestInit ( method , pathname , requestId , userId , orgId ) ;
34+ } catch ( error ) {
35+ // Silently fail logging for dev server requests
36+ }
37+ }
2638
2739 // Set request ID header
2840 req . headers [ 'x-request-id' ] = requestId ;
2941
3042 // Capture original end function to log response
3143 const originalEnd = res . end . bind ( res ) ;
3244 res . end = function ( ...args : any [ ] ) {
33- const latency = Date . now ( ) - requestStart ;
34- logResponse ( method , pathname , requestId , latency , res . statusCode || 200 ) ;
45+ if ( ! isTanStackSplitRequest && ! isViteInternal ) {
46+ try {
47+ const latency = Date . now ( ) - requestStart ;
48+ logResponse ( method , pathname , requestId , latency , res . statusCode || 200 ) ;
49+ } catch ( error ) {
50+ // Silently fail logging for dev server requests
51+ }
52+ }
3553 return originalEnd ( ...args ) ;
3654 } ;
3755
@@ -50,6 +68,18 @@ export default defineConfig(({ mode }) => {
5068 . filter ( Boolean ) ;
5169
5270 return {
71+ base : '/' ,
72+ build : {
73+ // Ensure proper asset handling for TanStack Start
74+ rollupOptions : {
75+ output : {
76+ // Ensure consistent asset naming
77+ assetFileNames : 'assets/[name]-[hash][extname]' ,
78+ chunkFileNames : 'assets/[name]-[hash].js' ,
79+ entryFileNames : 'assets/[name]-[hash].js' ,
80+ } ,
81+ } ,
82+ } ,
5383 ssr : {
5484 // Force native Node resolution at runtime (no inlining)
5585 external : [ '@workos-inc/node' ] ,
@@ -58,13 +88,18 @@ export default defineConfig(({ mode }) => {
5888 server : {
5989 port : 3030 ,
6090 allowedHosts,
91+ // Ensure proper handling of dynamic imports and component splitting
92+ hmr : {
93+ protocol : 'ws' ,
94+ } ,
6195 } ,
6296 plugins : [
6397 tsConfigPaths ( {
6498 projects : [ './tsconfig.json' ] ,
6599 } ) ,
66- requestLoggingPlugin ( ) ,
100+ // TanStack Start must come before request logging to handle component splitting
67101 tanstackStart ( ) ,
102+ requestLoggingPlugin ( ) ,
68103 viteReact ( ) ,
69104 // cloudflare({ viteEnvironment: { name: 'ssr' } }),
70105 ] ,
0 commit comments