@@ -221,6 +221,30 @@ function devCompressionPlugin(): Plugin { |
221 | 221 | }; |
222 | 222 | } |
223 | 223 |
|
| 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 | + |
224 | 248 | // Allow Tailnet hosts for sharing; Tailscale-controlled DNS prevents attacker rebinding. |
225 | 249 | const configuredAllowedHosts = (process.env.T3CODE_DEV_ALLOWED_HOSTS ?? "") |
226 | 250 | .split(",") |
@@ -242,6 +266,7 @@ export default defineConfig(() => { |
242 | 266 | assetsInclude: ["**/*.wasm"], |
243 | 267 | plugins: [ |
244 | 268 | devCompressionPlugin(), |
| 269 | + chunkCycleGuardPlugin(), |
245 | 270 | builtDev |
246 | 271 | ? undefined |
247 | 272 | : thirdPartyLicensesPlugin({ |
@@ -359,21 +384,6 @@ export default defineConfig(() => { |
359 | 384 | asset.originalFileNames.some((path) => /[/\\]pdfjs-dist[/\\]wasm[/\\]/.test(path)) |
360 | 385 | ? `assets/pdfjs-${pdfjsPkg.version}/[name][extname]` |
361 | 386 | : "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: /\/node_modules\/(?:react|react-dom|scheduler)\//, |
368 | | - includeDependenciesRecursively: false, |
369 | | - }, |
370 | | - { |
371 | | - name: "icons", |
372 | | - test: /\/(?:components\/chat\/PierreEntryIcon\.tsx|pierre-icons\.ts|mediaPreview\.ts)$/, |
373 | | - includeDependenciesRecursively: false, |
374 | | - }, |
375 | | - ], |
376 | | - }, |
377 | 387 | }, |
378 | 388 | }, |
379 | 389 | }, |
|