@@ -618,10 +618,27 @@ async function kit({ svelte_config }) {
618
618
/** @type {Array<{ hash: string, file: string }> } */
619
619
const remotes = [ ] ;
620
620
621
+ /**
622
+ * A set of modules that imported by `.remote.ts` modules. By forcing these modules
623
+ * into their own chunks, we ensure that each chunk created for a `.remote.ts`
624
+ * module _only_ contains that module, hopefully avoiding any circular
625
+ * dependency woes that arise from treating chunks as entries
626
+ */
627
+ const imported_by_remotes = new Set ( ) ;
628
+ let uid = 1 ;
629
+
621
630
/** @type {import('vite').Plugin } */
622
631
const plugin_remote = {
623
632
name : 'vite-plugin-sveltekit-remote' ,
624
633
634
+ moduleParsed ( info ) {
635
+ if ( svelte_config . kit . moduleExtensions . some ( ( ext ) => info . id . endsWith ( `.remote${ ext } ` ) ) ) {
636
+ for ( const id of info . importedIds ) {
637
+ imported_by_remotes . add ( id ) ;
638
+ }
639
+ }
640
+ } ,
641
+
625
642
config ( config ) {
626
643
if ( ! config . build ?. ssr ) {
627
644
// only set manualChunks for the SSR build
@@ -644,21 +661,17 @@ async function kit({ svelte_config }) {
644
661
config . build . rollupOptions . output = {
645
662
...config . build . rollupOptions . output ,
646
663
manualChunks ( id , meta ) {
647
- // Prevent core runtime and env from ending up in a remote chunk, which could break because of initialization order
648
- if ( id === `${ runtime_directory } /app/server/index.js` ) {
649
- return 'app-server' ;
650
- }
651
- if ( id === `${ runtime_directory } /shared-server.js` ) {
652
- return 'app-shared-server' ;
653
- }
654
-
655
664
// Check if this is a *.remote.ts file
656
665
if ( svelte_config . kit . moduleExtensions . some ( ( ext ) => id . endsWith ( `.remote${ ext } ` ) ) ) {
657
666
const relative = posixify ( path . relative ( cwd , id ) ) ;
658
667
659
668
return `remote-${ hash ( relative ) } ` ;
660
669
}
661
670
671
+ if ( imported_by_remotes . has ( id ) ) {
672
+ return `chunk-${ uid ++ } ` ;
673
+ }
674
+
662
675
// If there was an existing manualChunks function, call it
663
676
if ( typeof manualChunks === 'function' ) {
664
677
return manualChunks ( id , meta ) ;
0 commit comments