@@ -564,6 +564,65 @@ Deno.test({
564564 sanitizeResources : false ,
565565} ) ;
566566
567+ // issue: https://github.com/freshframework/fresh/issues/3895
568+ // Vite appends a `?v=<hash>` suffix to dependency ids when `optimizeDeps` is
569+ // active. The Deno loader must strip it instead of treating it as part of the
570+ // file path, in both the client and the ssr environment.
571+ integrationTest ( "vite dev - works with optimizeDeps enabled" , async ( ) => {
572+ const fixture = path . join ( FIXTURE_DIR , "no_islands" ) ;
573+ await using tmp = await prepareDevServer ( fixture , {
574+ config : `import { defineConfig } from "vite";
575+ import { fresh } from "@fresh/plugin-vite";
576+
577+ export default defineConfig({
578+ plugins: [fresh()],
579+ optimizeDeps: { include: ["preact"] },
580+ environments: {
581+ ssr: { optimizeDeps: { include: ["preact"] } },
582+ },
583+ });
584+ ` ,
585+ } ) ;
586+
587+ await launchDevServer ( tmp . dir , async ( address ) => {
588+ // ssr environment
589+ const res = await fetch ( address ) ;
590+ const text = await res . text ( ) ;
591+ expect ( res . status ) . toEqual ( 200 ) ;
592+ expect ( text ) . toContain ( "ok" ) ;
593+
594+ // client environment: walk the module graph from the client entry. Vite
595+ // versions dependency ids whether or not it pre-bundles them, so the
596+ // graph contains `?v=<hash>` urls that must still resolve to a file.
597+ const seen = new Set < string > ( ) ;
598+ const queue = [ "/@id/fresh:client-entry" ] ;
599+ const failed : string [ ] = [ ] ;
600+ let versioned = 0 ;
601+
602+ while ( queue . length > 0 ) {
603+ const url = queue . pop ( ) ! ;
604+ if ( seen . has ( url ) || url . startsWith ( "/@vite/" ) ) continue ;
605+ seen . add ( url ) ;
606+
607+ const modRes = await fetch ( `${ address } ${ url } ` ) ;
608+ const code = await modRes . text ( ) ;
609+ if ( modRes . status !== 200 ) {
610+ failed . push ( `${ modRes . status } ${ url } ` ) ;
611+ continue ;
612+ }
613+
614+ if ( url . includes ( "?v=" ) ) versioned ++ ;
615+
616+ for ( const match of code . matchAll ( / f r o m " ( \/ [ ^ " ] + ) " / g) ) {
617+ queue . push ( match [ 1 ] ) ;
618+ }
619+ }
620+
621+ expect ( failed ) . toEqual ( [ ] ) ;
622+ expect ( versioned ) . toBeGreaterThan ( 0 ) ;
623+ } ) ;
624+ } ) ;
625+
567626// issue: https://github.com/denoland/fresh/issues/3666
568627integrationTest (
569628 "vite dev - basePath does not intercept Vite URLs" ,
0 commit comments