:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(frontend): move stable chunk names into the frontend build scripts (#105822)
Paul D'Ambra35b91a4b9829
diff --git a/Dockerfile b/Dockerfileindex cb61985f86a4..c43efb212fc8 100644--- a/Dockerfile+++ b/Dockerfile@@ -83,7 +83,7 @@ COPY --from=frontend-build /code/frontend/dist /code/frontend/dist# "retained" and the .map files are kept in the image. Uses explicit && chaining rather than `set -e`,# which bash ignores inside a `||`-guarded subshell — any failing link drops us into the retained branch.#-# Two passes. The stable-name copies (`*-S<10 hex>.js`, see common/esbuilder/stableChunkNames.mjs) keep+# Two passes. The stable-name copies (`*-S<10 hex>.js`, see frontend/bin/stableChunkNames.mjs) keep# one URL for as long as their code is unchanged, so they must not carry the per-release id that the# first pass injects. The second pass runs with no release flags and without GITHUB_ACTIONS, so the CLI# resolves no release and injects only the chunk id, which it derives from the file's own content.diff --git a/common/esbuilder/utils.mjs b/common/esbuilder/utils.mjsindex 484e077452c3..452f4e44721c 100644--- a/common/esbuilder/utils.mjs+++ b/common/esbuilder/utils.mjs@@ -167,7 +167,7 @@ export function copyIndexHtml(}// With stable chunk names built, the backend picks the boot variant per request. See- // stableChunkNames.mjs and the stable_chunks context in posthog/utils.py.+ // frontend/bin/stableChunkNames.mjs and the stable_chunks context in posthog/utils.py.const scripts = stable? `{% if stable_chunks %}${bootScript(stable.chunks, stable.entrypoints, { isStable: true, eagerCss: stable.eagerCss ?? [] })}{% else %}${bootScript(chunks, entrypoints)}{% endif %}`: bootScript(chunks, entrypoints)diff --git a/common/esbuilder/stableChunkNames.mjs b/frontend/bin/stableChunkNames.mjssimilarity index 98%rename from common/esbuilder/stableChunkNames.mjsrename to frontend/bin/stableChunkNames.mjsindex d41bfae489ca..2c55844b47c5 100644--- a/common/esbuilder/stableChunkNames.mjs+++ b/frontend/bin/stableChunkNames.mjs@@ -64,7 +64,7 @@ export function rewriteChunkSource(source, identityByFile) {export function stableFileName(originalFile, rewrittenSource) {const prefix = originalFile.replace(/-[^-./]+\.js$/, '')- // Only holds because chunkNames/entryNames in utils.mjs are `[name]-[hash]` for non-dev builds.+ // Only holds because chunkNames/entryNames in common/esbuilder/utils.mjs are `[name]-[hash]` for non-dev builds.// Fail loudly rather than silently producing a garbled name like `index.js-S....js`.if (prefix === originalFile) {throw new Error(`stable chunks: ${originalFile} does not end in the expected -<hash>.js suffix`)diff --git a/common/esbuilder/stableChunkNames.test.ts b/frontend/bin/stableChunkNames.test.tssimilarity index 100%rename from common/esbuilder/stableChunkNames.test.tsrename to frontend/bin/stableChunkNames.test.tsdiff --git a/frontend/bin/stableCssPlan.mjs b/frontend/bin/stableCssPlan.mjsindex e8dc10288102..cf27a4ab3dab 100644--- a/frontend/bin/stableCssPlan.mjs+++ b/frontend/bin/stableCssPlan.mjs@@ -1,7 +1,7 @@import { CSS_LOAD_GLOBAL } from '@posthog/esbuilder/cssLoader.mjs'-import { chunkIdentity, shortHash } from '@posthog/esbuilder/stableChunkNames.mjs'import { BOOT_ENTRIES, ENTRY } from './bootEntries.mjs'+import { chunkIdentity, shortHash } from './stableChunkNames.mjs'/*** Split stylesheets for the stable build.diff --git a/frontend/build.mjs b/frontend/build.mjsindex c22ffb7a0346..1b35a3dfffee 100755--- a/frontend/build.mjs+++ b/frontend/build.mjs@@ -14,8 +14,8 @@ import {reportTopChunks,startDevServer,} from '@posthog/esbuilder'-import { writeStableChunks } from '@posthog/esbuilder/stableChunkNames.mjs'+import { writeStableChunks } from './bin/stableChunkNames.mjs'import { buildCssGroups } from './bin/stableCss.mjs'import { cssPrelude, CSS_SPECIFIER_PREFIX, planCssGroups } from './bin/stableCssPlan.mjs'import { finalizeToolbarBuild, getToolbarAppBuildConfig } from './toolbar-config.mjs'diff --git a/posthog/stable_chunks.py b/posthog/stable_chunks.pyindex 1ff23d317865..c11884c2905a 100644--- a/posthog/stable_chunks.py+++ b/posthog/stable_chunks.py@@ -3,7 +3,7 @@ Opt-in serving of the frontend build with stable chunk names.The build writes a second copy of the app's JS in which chunks import each other through identityspecifiers, plus `stable-chunks-manifest.json` with the import map that resolves them (see-common/esbuilder/stableChunkNames.mjs). A chunk's URL then changes only when its own code changes,+frontend/bin/stableChunkNames.mjs). A chunk's URL then changes only when its own code changes,so a deploy no longer makes returning users download every chunk that imports a changed one.Serving it is opt-in per browser while it is tested: `?stable_chunks=1` sets a cookie and