Skip to content

: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.

perf(frontend): drop unused icons from the boot path (#104886)

posthog[bot]fbe31d1eba09
diff --git a/common/esbuilder/utils.mjs b/common/esbuilder/utils.mjs
index 7a32638c3799..3ccf683697ae 100644
--- a/common/esbuilder/utils.mjs
+++ b/common/esbuilder/utils.mjs
@@ -242,6 +242,29 @@ export const commonConfig = {
)
},
},
+ // @posthog/icons declares each of its 300+ icons as `const IconFoo = forwardRef(...)` in
+ // one ES bundle. A bundler cannot prove a bare call is side-effect free, so every entry
+ // point that renders a single icon ships the whole set (~260 KiB on the boot path).
+ // forwardRef only wraps its argument, so annotate the calls and let tree shaking keep
+ // the icons a chunk actually renders. Drop this once the package annotates them itself.
+ {
+ name: 'icons-pure-annotations',
+ setup(build) {
+ build.onLoad({ filter: /@posthog[\\/]icons[\\/]dist[\\/][^\\/]+\.es\.js$/ }, async (args) => {
+ const source = await fs.readFile(args.path, 'utf8')
+ const contents = source.replace(
+ /^const ([A-Za-z0-9_$]+) = forwardRef\(/gm,
+ 'const $1 = /* @__PURE__ */ forwardRef('
+ )
+ if (contents === source) {
+ // Bundle shape changed upstream - fail loudly rather than silently
+ // reshipping the whole icon set on every page.
+ throw new Error(`icons-pure-annotations: no icon declarations found in ${args.path}`)
+ }
+ return { contents, loader: 'js' }
+ })
+ },
+ },
// monaco-vim imports monaco-editor internals without .js extensions (e.g. monaco-editor/esm/vs/editor/editor.api)
// which esbuild can't resolve through monaco-editor's package.json exports map
{
diff --git a/frontend/src/sharedChunkAnchors.ts b/frontend/src/sharedChunkAnchors.ts
index 06f89ccff252..bf6c2f616f87 100644
--- a/frontend/src/sharedChunkAnchors.ts
+++ b/frontend/src/sharedChunkAnchors.ts
@@ -30,8 +30,6 @@ import * as ReactDom from 'react-dom'
import * as ReactDomClient from 'react-dom/client'
import * as Zod from 'zod'
-import * as PosthogIcons from '@posthog/icons'
-
export const __chunkAnchors = {
DndKitCore,
HighlightJsCore,
@@ -44,7 +42,6 @@ export const __chunkAnchors = {
KeaWindowValues,
Liquidjs,
Marked,
- PosthogIcons,
PosthogJs,
PosthogRrweb,
React,