Skip to content

Commit 04a21bb

Browse files
t3dotggclaude
andauthored
fix(web): app loads again after a chunk cycle blanked it at boot (pingdotgg#25295)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1de6494 commit 04a21bb

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

‎apps/web/vite.config.ts‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
225249
const 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) => /[/\\]pdfjs-dist[/\\]wasm[/\\]/.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: /\/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-
},
377387
},
378388
},
379389
},

0 commit comments

Comments
 (0)