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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: pin the three stack to vendor-three and guard chunk groups against dead packages (#5725)
Adam Eivy43c006450090
diff --git a/client/src/test/viteChunkGroups.test.js b/client/src/test/viteChunkGroups.test.jsnew file mode 100644index 0000000000..30def00294--- /dev/null+++ b/client/src/test/viteChunkGroups.test.js@@ -0,0 +1,55 @@+import { existsSync, readdirSync } from 'node:fs';+import { resolve } from 'node:path';++import { describe, expect, it } from 'vitest';++import { CHUNK_GROUPS } from '../../vite.chunkGroups.js';++const CLIENT_DIR = resolve(import.meta.dirname, '../..');+// Client deps install into client/node_modules; a few hoist to the repo root.+const NODE_MODULES_DIRS = [+ resolve(CLIENT_DIR, 'node_modules'),+ resolve(CLIENT_DIR, '../node_modules'),+].filter(existsSync);++const isInstalled = (name) => NODE_MODULES_DIRS.some((dir) => (+ name.endsWith('*')+ ? readdirSync(dir).some((entry) => entry.startsWith(name.slice(0, -1)))+ : existsSync(resolve(dir, name))+));++const groupNamed = (name) => CHUNK_GROUPS.find((group) => group.name === name);++describe('vite chunk groups', () => {+ // The regression: a group regex naming a package that is not installed matches+ // nothing, so the named chunk quietly stops capturing what its comment claims.+ // `vendor-three` shipped that way against the removed `three-fenestra` (#5725).+ it('only names packages that are actually installed', () => {+ const missing = CHUNK_GROUPS.flatMap(({ name, packages }) =>+ packages.filter((pkg) => !isInstalled(pkg)).map((pkg) => `${name} -> ${pkg}`));+ expect(NODE_MODULES_DIRS.length).toBeGreaterThan(0);+ expect(missing).toEqual([]);+ });++ 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);+ });++ it('keeps package names from bleeding across the separator', () => {+ // `react` must not swallow `react-router-dom` or a nested `react` copy's+ // sibling; the trailing separator is what enforces a whole-segment match.+ const { test } = groupNamed('vendor-react');+ expect(test.test('/app/node_modules/react/index.js')).toBe(true);+ expect(test.test('/app/node_modules/react-redux/index.js')).toBe(false);+ // Family prefixes still match every member.+ const charts = groupNamed('vendor-charts').test;+ expect(charts.test('/app/node_modules/d3-scale/src/band.js')).toBe(true);+ expect(charts.test('/app/node_modules/victory-vendor/d3-scale.js')).toBe(true);+ });+});diff --git a/client/vite.chunkGroups.js b/client/vite.chunkGroups.jsnew file mode 100644index 0000000000..23c830cbdc--- /dev/null+++ b/client/vite.chunkGroups.js@@ -0,0 +1,50 @@+// Vendor chunk groups for rolldown's `output.codeSplitting.groups` (Vite 8).+//+// Declared as package NAMES rather than as hand-written regexes so the grouping+// can be checked against what is actually installed. A group regex naming a+// package nobody installs matches nothing and quietly stops guaranteeing+// anything: `vendor-three` listed `three-fenestra` — removed from the tree when+// `openworld/InteriorMappingMaterial.js` ported the material in — while the two+// three-* packages that DO ship (`three-stdlib` and `three-mesh-bvh`, both pulled+// in by @react-three/drei) fell outside the pattern, because `three` had to be+// followed immediately by a path separator (#5725).+//+// Conventions for a `packages` entry:+// 'three' an exact package name+// '@xterm' a scope — every package published under it+// 'd3-*' a family prefix — every `d3-<something>` package+// `buildGroupTest` renders them back into the module-id regex rolldown matches+// with. Use `[\\/]` (not `/`) for the separator so the regexes match on Windows.++const PATH_SEP = '[\\\\/]';++const escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');++const packagePattern = (name) =>+ name.endsWith('*')+ ? `${escapeRegex(name.slice(0, -1))}[^\\\\/]+`+ : escapeRegex(name);++/** Module-id regex capturing every module published by one of `packages`. */+const buildGroupTest = (packages) =>+ new RegExp(`${PATH_SEP}node_modules${PATH_SEP}(${packages.map(packagePattern).join('|')})${PATH_SEP}`);++export const CHUNK_GROUPS = [+ // Core React dependencies+ { name: 'vendor-react', packages: ['react', 'react-dom', 'react-router'] },+ // Socket dependencies+ { name: 'vendor-realtime', packages: ['socket.io-client'] },+ // Drag and drop library (only used in CoS)+ { name: 'vendor-dnd', packages: ['@dnd-kit'] },+ // Icon library (largest dependency)+ { name: 'vendor-icons', packages: ['lucide-react'] },+ // 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'] },+ // Charting (recharts) — lazy chart pages only+ { name: 'vendor-charts', packages: ['recharts', 'd3-*', 'victory-*'] },+ // Terminal emulator (xterm) — Shell page only+ { name: 'vendor-term', packages: ['@xterm'] },+].map((group) => ({ ...group, test: buildGroupTest(group.packages) }));diff --git a/client/vite.config.js b/client/vite.config.jsindex 8b2d11a8b4..8c3044bdb0 100644--- a/client/vite.config.js+++ b/client/vite.config.js@@ -6,6 +6,7 @@ import { execFileSync } from 'child_process';import { resolve } from 'path';import { resolveBundleNodeEnv } from './vite.buildEnv.js';+import { CHUNK_GROUPS } from './vite.chunkGroups.js';const ANALYZE_BUNDLE = process.env.ANALYZE === 'true';const CONFIG_DIR = import.meta.dirname;@@ -171,29 +172,11 @@ export default defineConfig(({ command, mode }) => {// id matches `test` into a named chunk. This replaces the legacy// `rollupOptions.output.manualChunks` function (still accepted via// rolldown's compat layer, but slated to drop in a future Vite). The- // groups below reproduce the same four vendor chunks as before.- // Note: use `[\\/]` (not `/`) for the path separator so the regexes- // also match on Windows.+ // groups themselves are declared as package names in+ // `vite.chunkGroups.js`, so a group naming an uninstalled package fails+ // a test instead of silently grouping nothing.codeSplitting: {- groups: [- // Core React dependencies- { name: 'vendor-react', test: /[\\/]node_modules[\\/](react|react-dom|react-router)[\\/]/ },- // Socket dependencies- { name: 'vendor-realtime', test: /[\\/]node_modules[\\/]socket\.io-client[\\/]/ },- // Drag and drop library (only used in CoS)- { name: 'vendor-dnd', test: /[\\/]node_modules[\\/]@dnd-kit[\\/]/ },- // Icon library (largest dependency)- { name: 'vendor-icons', test: /[\\/]node_modules[\\/]lucide-react[\\/]/ },- // 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 guarantees a single- // shared chunk across all 3D consumers.- { name: 'vendor-three', test: /[\\/]node_modules[\\/](three|@react-three|three-fenestra)[\\/]/ },- // Charting (recharts) — lazy chart pages only- { name: 'vendor-charts', test: /[\\/]node_modules[\\/](recharts|d3-[^\\/]+|victory-[^\\/]+)[\\/]/ },- // Terminal emulator (xterm) — Shell page only- { name: 'vendor-term', test: /[\\/]node_modules[\\/]@xterm[\\/]/ },- ]+ groups: CHUNK_GROUPS.map(({ name, test }) => ({ name, test }))}}},