@@ -221,6 +221,30 @@ function devCompressionPlugin(): Plugin {
221221 } ;
222222}
223223
224+ // A static import cycle between chunks can run a chunk before the values it imports exist,
225+ // which blanks the app at boot. Fail the build instead of shipping it.
226+ function chunkCycleGuardPlugin ( ) : Plugin {
227+ return {
228+ name : "t3code:chunk-cycle-guard" ,
229+ apply : "build" ,
230+ generateBundle ( _options , bundle ) {
231+ const done = new Set < string > ( ) ;
232+ const visit = ( fileName : string , path : string [ ] ) => {
233+ if ( done . has ( fileName ) ) return ;
234+ const start = path . indexOf ( fileName ) ;
235+ if ( start !== - 1 ) {
236+ this . error ( `Chunk import cycle: ${ [ ...path . slice ( start ) , fileName ] . join ( " -> " ) } ` ) ;
237+ }
238+ const chunk = bundle [ fileName ] ;
239+ if ( chunk ?. type !== "chunk" ) return ;
240+ for ( const imported of chunk . imports ) visit ( imported , [ ...path , fileName ] ) ;
241+ done . add ( fileName ) ;
242+ } ;
243+ for ( const fileName of Object . keys ( bundle ) ) visit ( fileName , [ ] ) ;
244+ } ,
245+ } ;
246+ }
247+
224248// Allow Tailnet hosts for sharing; Tailscale-controlled DNS prevents attacker rebinding.
225249const configuredAllowedHosts = ( process . env . T3CODE_DEV_ALLOWED_HOSTS ?? "" )
226250 . split ( "," )
@@ -242,6 +266,7 @@ export default defineConfig(() => {
242266 assetsInclude : [ "**/*.wasm" ] ,
243267 plugins : [
244268 devCompressionPlugin ( ) ,
269+ chunkCycleGuardPlugin ( ) ,
245270 builtDev
246271 ? undefined
247272 : thirdPartyLicensesPlugin ( {
@@ -359,21 +384,6 @@ export default defineConfig(() => {
359384 asset . originalFileNames . some ( ( path ) => / [ / \\ ] p d f j s - d i s t [ / \\ ] w a s m [ / \\ ] / . test ( path ) )
360385 ? `assets/pdfjs-${ pdfjsPkg . version } /[name][extname]`
361386 : "assets/[name]-[hash][extname]" ,
362- codeSplitting : {
363- // Preview imports must not fold shared file icons back into main.
364- groups : [
365- {
366- name : "react" ,
367- test : / \/ n o d e _ m o d u l e s \/ (?: r e a c t | r e a c t - d o m | s c h e d u l e r ) \/ / ,
368- includeDependenciesRecursively : false ,
369- } ,
370- {
371- name : "icons" ,
372- test : / \/ (?: c o m p o n e n t s \/ c h a t \/ P i e r r e E n t r y I c o n \. t s x | p i e r r e - i c o n s \. t s | m e d i a P r e v i e w \. t s ) $ / ,
373- includeDependenciesRecursively : false ,
374- } ,
375- ] ,
376- } ,
377387 } ,
378388 } ,
379389 } ,
0 commit comments