Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: split three-stdlib loaders out of the shared vendor-three chunk

[._.]/ Adam Eivy41a3fb4f0f07
diff --git a/client/src/test/viteChunkGroups.test.js b/client/src/test/viteChunkGroups.test.js
index 54034ba5c3..614a56d86e 100644
--- a/client/src/test/viteChunkGroups.test.js
+++ b/client/src/test/viteChunkGroups.test.js
@@ -51,11 +51,19 @@ describe('vite chunk groups', () => {
it('captures the whole three stack on both path separators', () => {
const { test } = groupNamed('vendor-three');
expect(test.test('/app/node_modules/three/build/three.module.js')).toBe(true);
- expect(test.test('/app/node_modules/three-stdlib/index.js')).toBe(true);
expect(test.test('/app/node_modules/three-mesh-bvh/src/index.js')).toBe(true);
expect(test.test('C:\\app\\node_modules\\@react-three\\fiber\\index.js')).toBe(true);
// A `three`-prefixed package we do not depend on must not be swept in.
expect(test.test('/app/node_modules/three-globe/index.js')).toBe(false);
+ // three-stdlib (loaders/exporters) is split into its own chunk (#8146).
+ expect(test.test('/app/node_modules/three-stdlib/index.js')).toBe(false);
+ });
+
+ it('isolates the three-stdlib loaders/exporters into their own chunk (#8146)', () => {
+ const { test } = groupNamed('vendor-three-loaders');
+ expect(test.test('/app/node_modules/three-stdlib/loaders/GLTFLoader.js')).toBe(true);
+ expect(test.test('C:\\app\\node_modules\\three-stdlib\\exporters\\USDZExporter.js')).toBe(true);
+ expect(test.test('/app/node_modules/three/build/three.module.js')).toBe(false);
});
it('keeps package names from bleeding across the separator', () => {
diff --git a/client/vite.chunkGroups.js b/client/vite.chunkGroups.js
index 23c830cbdc..20f3c63a04 100644
--- a/client/vite.chunkGroups.js
+++ b/client/vite.chunkGroups.js
@@ -29,6 +29,22 @@ const packagePattern = (name) =>
const buildGroupTest = (packages) =>
new RegExp(`${PATH_SEP}node_modules${PATH_SEP}(${packages.map(packagePattern).join('|')})${PATH_SEP}`);
+// Rolldown's `includeDependenciesRecursively` defaults to true: a group also
+// captures every transitive dependency of a module it directly matches, not
+// just the modules its own `test` names. Left at its default, `vendor-three`
+// matching `@react-three` (drei) recursively pulls in ALL of `three-stdlib` as
+// drei's dependency — silently defeating the `vendor-three-loaders` split
+// below, because that group is declared (and thus processed) second and never
+// sees those modules to claim; rolldown removes a module from every other
+// group once one group has captured it (first-declared wins on a tie). Turning
+// recursion off HERE, and declaring `vendor-three-loaders` first, makes it the
+// one that claims `three-stdlib`'s own modules before `vendor-three`'s walk
+// can reach them — while `vendor-three` keeps its default recursive capture,
+// which is what pulls drei/fiber's OTHER transitive runtime deps (troika text
+// rendering, camera-controls, meshline, zustand, …) into the shared chunk
+// instead of duplicating them into every individual page that uses drei.
+const DIRECT_MATCH_ONLY = { includeDependenciesRecursively: false };
+
export const CHUNK_GROUPS = [
// Core React dependencies
{ name: 'vendor-react', packages: ['react', 'react-dom', 'react-router'] },
@@ -38,11 +54,22 @@ export const CHUNK_GROUPS = [
{ name: 'vendor-dnd', packages: ['@dnd-kit'] },
// Icon library (largest dependency)
{ name: 'vendor-icons', packages: ['lucide-react'] },
+ // GLTF/DRACO/Meshopt/KTX2/HDR loaders and the USDZ exporter — all published
+ // from `three-stdlib` — split out of `vendor-three` (#8146). Declared BEFORE
+ // `vendor-three` so it claims these modules directly; see the
+ // `DIRECT_MATCH_ONLY` note above for why order and recursion matter here.
+ // They are pulled in only by pages that load an actual asset (Model Detail,
+ // AR export, HDRI environments, and the CoS avatars that call `useGLTF`);
+ // the procedural graph surfaces (Brain/Memory graph, Goals tree, GraphScene)
+ // never import them and previously paid for this chunk anyway because
+ // rolldown grouped every three-stdlib module into one package-wide chunk.
+ { name: 'vendor-three-loaders', packages: ['three-stdlib'], ...DIRECT_MATCH_ONLY },
// 3D stack — only pulled into lazy 3D pages (CyberCity, avatars, BrainGraph).
- // Naming it gives the ~1 MB chunk a stable identity instead of an opaque
- // `OrbitControls-*.js`, and listing drei's own three-* dependencies pins them
- // to that chunk instead of leaving their placement to the bundler's derivation.
- { name: 'vendor-three', packages: ['three', 'three-stdlib', 'three-mesh-bvh', '@react-three'] },
+ // Naming it gives the chunk a stable identity instead of an opaque
+ // `OrbitControls-*.js`, and listing drei's own three-* dependencies pins
+ // them to that chunk instead of leaving their placement to the bundler's
+ // derivation.
+ { name: 'vendor-three', packages: ['three', 'three-mesh-bvh', '@react-three'] },
// Charting (recharts) — lazy chart pages only
{ name: 'vendor-charts', packages: ['recharts', 'd3-*', 'victory-*'] },
// Terminal emulator (xterm) — Shell page only
diff --git a/client/vite.config.js b/client/vite.config.js
index 22d8fa3910..21425b2d20 100644
--- a/client/vite.config.js
+++ b/client/vite.config.js
@@ -224,14 +224,34 @@ export default defineConfig(({ command, mode }) => {
// `vite.chunkGroups.js`, so a group naming an uninstalled package fails
// a test instead of silently grouping nothing.
codeSplitting: {
- groups: CHUNK_GROUPS.map(({ name, test }) => ({ name, test }))
+ // Pass every rolldown-recognized field through — not just
+ // `name`/`test`. A narrower destructure here silently drops group
+ // options like `includeDependenciesRecursively` before rolldown
+ // ever sees them (#8146): the config value looks right when you
+ // print `CHUNK_GROUPS`, but the build behaves as if it were never
+ // set. `packages` is `vite.chunkGroups.js`'s own bookkeeping (used
+ // to derive `test` and by its installed-package test), not a
+ // rolldown option, so it's the one field left out here.
+ groups: CHUNK_GROUPS.map(({ packages, ...group }) => group)
}
}
},
// Enable source maps for debugging in production
sourcemap: false,
- // Increase chunk size warning limit (icons are large)
- chunkSizeWarningLimit: 600
+ // Chunk size warning budget (#8146). `vendor-three` — three.js core plus
+ // @react-three/fiber and drei's own runtime (troika text rendering,
+ // camera-controls, meshline, zustand, …), all lazy-loaded and shared by
+ // every 3D page (Model Detail, Brain/Memory graph, Goals tree, CoS
+ // avatars) — measures ~1.08 MB minified / ~300 KB gzip. That floor is
+ // three.js's own footprint, not something PortOS's imports control: the
+ // GLTF/DRACO/KTX2/HDR loaders and the USDZ exporter are already split
+ // into their own `vendor-three-loaders` chunk (~114 KB / ~35 KB gzip)
+ // that only pages actually loading an asset pay for, and drei's helper
+ // runtime is deliberately kept IN `vendor-three` rather than
+ // re-duplicated into each page's own chunk (see `vite.chunkGroups.js`).
+ // 1200 KB gives `vendor-three` headroom without silencing every other
+ // chunk's real regression budget.
+ chunkSizeWarningLimit: 1200
}
};
});