From 352d7cac9a18aaf1dbc7752a6fe91d93febd5e7c Mon Sep 17 00:00:00 2001 From: Makisuo Date: Wed, 25 Nov 2026 00:33:24 +0100 Subject: [PATCH] fix(sourcemaps): split web into eager chunks under the map cap, skip maps with no sources The web index chunk's map was 37.5 MiB, over the 10 MiB upload cap, so the main bundle never symbolicated. Eager code-split groups (vendor, kit, app; up to 2.5 MB each, entry aware, strict execution order) keep every map under 4.5 MiB with nothing lazy-loaded. A prebuilt worker's map lists no sources; the server refused it and failed every prd deploy that built web. The uploader now skips such maps with a warning. --- apps/web/vite.config.ts | 29 ++++++++++++++++++- packages/alchemy-maple/src/SourceMaps.ts | 6 ++-- .../alchemy-maple/test/source-maps.test.ts | 6 ++++ packages/sourcemaps/src/inject.ts | 14 +++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 3a12c91910..13d090c50b 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -150,6 +150,33 @@ export default defineConfig(({ mode, command }) => { ? [clerkEarlyLoad(clerkKey)] : []), ], - build: { manifest: true }, + build: { + manifest: true, + rolldownOptions: { + // Eager chunks under ~2.5 MB, so each source map stays under the 10 MiB upload cap. + // `entriesAware` keeps `boot` off the app's chunks; strict order keeps module init + // order across them (without it the app throws at startup). + output: { + strictExecutionOrder: true, + codeSplitting: { + groups: [ + { name: "vendor", test: /node_modules/, maxSize: 2_500_000, entriesAware: true }, + { + name: "kit", + test: /\/(packages|lib)\//, + maxSize: 2_500_000, + entriesAware: true, + }, + { + name: "app", + test: /\/apps\/web\/src\//, + maxSize: 2_500_000, + entriesAware: true, + }, + ], + }, + }, + }, + }, } }) diff --git a/packages/alchemy-maple/src/SourceMaps.ts b/packages/alchemy-maple/src/SourceMaps.ts index 011d1b5e7b..5b4499df33 100644 --- a/packages/alchemy-maple/src/SourceMaps.ts +++ b/packages/alchemy-maple/src/SourceMaps.ts @@ -6,6 +6,7 @@ import { findJsFiles, isIndexMap, MANIFEST_FILE, + mapsNoSources, mapDebugId, mapUsers, SourceMapsManifest, @@ -186,8 +187,9 @@ const hasRelease = (props: SourceMapsProps) => props.release !== undefined && pr /** Why a map is not uploaded, or none when it is. */ const skipReason = (props: SourceMapsProps, map: PlannedMap): Option.Option => { if (map.bytes.byteLength > SOURCE_MAP_MAX_BYTES) return Option.some("it is over 10 MiB") - if (isIndexMap(new TextDecoder().decode(map.bytes))) - return Option.some("index source maps are not supported") + const text = new TextDecoder().decode(map.bytes) + if (isIndexMap(text)) return Option.some("index source maps are not supported") + if (mapsNoSources(text)) return Option.some("it maps no sources") if (byRelease(props) && !hasRelease(props)) return Option.some('`matchBy: "release"` needs a release') if (Option.isNone(map.debugId) && !hasRelease(props)) return Option.some("it has no debug id and no release is set") diff --git a/packages/alchemy-maple/test/source-maps.test.ts b/packages/alchemy-maple/test/source-maps.test.ts index 8d89a75a75..807f7a54ac 100644 --- a/packages/alchemy-maple/test/source-maps.test.ts +++ b/packages/alchemy-maple/test/source-maps.test.ts @@ -186,6 +186,12 @@ describe("Maple.SourceMaps", () => { join(root, "big/huge.js.map"), `${Str.slice(0, -1)(map("src/huge.ts"))},"pad":"${Str.repeat(10 * 1024 * 1024)("x")}"}`, ) + // A prebuilt worker's map that lists no sources: the server refuses it, so it stays behind. + writeFileSync(join(root, "worker.js"), "w()\n") + writeFileSync( + join(root, "worker.js.map"), + JSON.stringify({ version: 3, sources: [], names: [], mappings: "" }), + ) return h.run( Effect.gen(function* () { // No release and no debug id: nothing can match the map, so nothing goes up. diff --git a/packages/sourcemaps/src/inject.ts b/packages/sourcemaps/src/inject.ts index 29acd23b7a..ffe7d1d36e 100644 --- a/packages/sourcemaps/src/inject.ts +++ b/packages/sourcemaps/src/inject.ts @@ -163,6 +163,20 @@ export const isIndexMap = (mapText: string): boolean => onSuccess: (map) => map["sections"] !== undefined, }) +/** + * Whether a plain map has no `mappings` string or no sources, which the server refuses. A prebuilt + * worker's map can list none. + */ +export const mapsNoSources = (mapText: string): boolean => + Result.match(decodeMap(mapText), { + onFailure: () => false, + onSuccess: (map) => + map["sections"] === undefined && + (!Predicate.isString(map["mappings"]) || + !Arr.isArray(map["sources"]) || + map["sources"].length === 0), + }) + /** A version 3 source map as a JSON object; anything else is never rewritten. */ const decodeV3Map = (mapText: string) => Option.filter(Result.getSuccess(decodeMap(mapText)), (map) => map["version"] === 3)