René's URL Explorer Experiment


Title: Allow third-party packages declaring `sideEffects: false` to opt out of `topLevelSafeMode` · Issue #33893 · angular/angular-cli · GitHub

Open Graph Title: Allow third-party packages declaring `sideEffects: false` to opt out of `topLevelSafeMode` · Issue #33893 · angular/angular-cli

X Title: Allow third-party packages declaring `sideEffects: false` to opt out of `topLevelSafeMode` · Issue #33893 · angular/angular-cli

Description: Command build Description markTopLevelPure only runs in its aggressive mode for files under node_modules/@angular/. For every other package the safe mode is active, and in safe mode no top-level call expression is ever annotated as pure ...

Open Graph Description: Command build Description markTopLevelPure only runs in its aggressive mode for files under node_modules/@angular/. For every other package the safe mode is active, and in safe mode no top-level ca...

X Description: Command build Description markTopLevelPure only runs in its aggressive mode for files under node_modules/@angular/. For every other package the safe mode is active, and in safe mode no top-level ca...

Opengraph URL: https://github.com/angular/angular-cli/issues/33893

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow third-party packages declaring `sideEffects: false` to opt out of `topLevelSafeMode`","articleBody":"### Command\n\nbuild\n\n### Description\n\n`markTopLevelPure` only runs in its aggressive mode for files under `node_modules/@angular/`. For every other package the safe mode is active, and in safe mode **no top-level call expression is ever annotated** as pure — only `new` expressions whose callee is in a one-entry allow-list (`InjectionToken`).\n\nThe consequence is that a third-party library cannot be tree-shaken past any top-level function call, even when it correctly declares `sideEffects: false`. And because the pure annotation has to sit at the **call site**, the authors of the called helper cannot fix it from their side either.\n\nThis hits a common pattern in styling libraries — `class-variance-authority`, `tailwind-variants`, and any `defineX()`-style helper:\n\n```ts\n// my-lib/ui/button.cva.ts — the package declares \"sideEffects\": false\nexport const buttonVariants = cva([\"inline-flex items-center\", /* … */]);\n```\n\nEvery such call and its string payload is retained in the consumer's bundle, whether or not the component that uses it is imported.\n\nRelevant code on `main`:\n\n- `packages/angular/build/src/tools/esbuild/javascript-transformer-worker.ts:211-213`\n  ```ts\n  const safeAngularPackage =\n    sideEffectFree && /[\\\\/]node_modules[\\\\/]@angular[\\\\/]/.test(filename);\n  const topLevelSafeMode = !safeAngularPackage;\n  ```\n- `packages/angular/build/src/tools/oxc/oxc-transform.ts:727` — `if (!pureAnnotate || functionDepth > 0 || classDepth > 0 || topLevelSafeMode) return;`\n- `packages/angular/build/src/tools/oxc/oxc-transform.ts:761-773` — in safe mode only `sideEffectFreeConstructors` is annotated, and that set is `new Set(['InjectionToken'])`.\n\nWorth noting that `sideEffectFree` already derives from the package's own `sideEffects: false` declaration — the field is read, and then trust is narrowed to first-party packages by the path test.\n\n**Impact, measured.** An Angular component library (23 components, `sideEffects: false`, ng-packagr FESM, 35 top-level `cva()` calls), consumed through its published FESM and bundled with the production pipeline (linker → advanced optimizations → esbuild `--minify`):\n\n| imported symbol | as published | with the 35 `cva()` calls manually annotated `/*#__PURE__*/` |\n| --- | --- | --- |\n| a 2-line pure string helper | 76 858 B | **1 472 B** |\n| a component using no variants | 77 229 B | **2 451 B** |\n| a simple button component | 77 452 B | **7 005 B** |\n| the most complex component | 86 513 B | **17 642 B** |\n\nTo be precise about what that figure is: it is what a **minimal** import retains, i.e. the cost of variants belonging to components the consumer never imports. It is not universal waste — an application that uses most of the library needs those variants anyway.\n\n**Measured counter-example**, same library: a real application importing 26 of its symbols (20 of them components) saw its production build change by 198 bytes out of 14 MB when the call sites were annotated — nothing. So the impact scales with how much of the library goes unused. That is the common case for a component library consumed selectively, and it is why the behaviour seems worth changing, but I would rather state the bound than overstate it.\n\nWorth noting too that this only affects consumers of the **published FESM**. Inside a workspace, where each `*.cva.ts` is still its own module, `sideEffects: false` already lets the whole module be dropped and no annotation is needed — the problem is specific to the flattened bundle, where elimination has to happen statement by statement.\n\n**Why the library side cannot solve it.** Same bundle, same function, esbuild 0.28.1:\n\n```js\n// lib.mjs\n// @__NO_SIDE_EFFECTS__\nexport function h(x) { return { v: x }; }\n\n// mid.mjs\nimport { h } from \"./lib.mjs\";\nexport const tiny = 1;\nexport const b1 = h(\"HHHH…\");                  // retained\nexport const b2 = /*@__PURE__*/ h(\"KKKK…\");    // eliminated\n```\n\nImporting only `tiny` keeps `b1` and drops `b2`. All three documented forms of `/*@__NO_SIDE_EFFECTS__*/` (line comment before `function`, block comment before `function`, block comment before the arrow of a `const`) left the call in place. Only the call-site annotation works — and the call site belongs to the consuming library, not to the helper. For reference, `cva@1.0.0-beta.8` does declare `sideEffects: false` and still ships no annotations, so an upstream release of the helper does not address this.\n\nI searched open and closed issues for `markTopLevelPure`, `safeAngularPackage`, `pure-toplevel-functions` and related tree-shaking terms before filing, and found nothing covering this.\n\n### Describe the solution you'd like\n\nSome way for an application to opt specific third-party packages into the aggressive mode — i.e. to disable `topLevelSafeMode` for packages it chooses to trust. What shape that takes, and whether it belongs in the build configuration at all, is for you to judge.\n\nThe reason for suggesting an opt-in rather than a change of default: some packages declare `sideEffects: false` incorrectly, so enabling the aggressive mode across all of `node_modules` could break existing apps. An opt-in leaves that call with the team that knows its own dependencies.\n\n### Describe alternatives you've considered\n\n1. **Drop the `node_modules/@angular/` path test**, letting the aggressive mode follow the `sideEffects: false` declaration a package already makes. Semantically the most correct reading of the field — it is precisely a promise that importing the module has no observable side effect — but it changes the default for every dependency at once, with the breakage risk noted above.\n2. **Extend `sideEffectFreeConstructors` into a call-expression allow-list** (e.g. `cva`, `tv`). Cheap, but arbitrary and endless, and it privileges specific libraries.\n3. **Annotate every top-level call site in the library.** This does work — the annotation survives `tsc` and `ng-packagr` into the published FESM. We tried it across three libraries (69 call sites) and then dropped it, because for our own main consumer the benefit measured as zero (the counter-example above); we were not willing to carry the churn and a lint rule for a gain we could not demonstrate. It is also invisible from the outside: nothing in the current behaviour hints that a library author should do this, which is why option 1 or 2 — or simply documenting it — seems more useful than leaving each library to rediscover it.\n","author":{"url":"https://github.com/hebus","@type":"Person","name":"hebus"},"datePublished":"2026-08-20T16:12:47Z","url":"https://github.com/angular/angular-cli/issues/33893"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:516e20ea-2f80-9339-0cd6-b7aa0f9793bf
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDC3C:1FE434:13423A2:196BBEB:6B01EE13
html-safe-nonce13c0ad6f5ccc2205e7dc0f92a6b2d7fefdda2aaab1b2a0adce37caf6e6239bfc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzNDOjFGRTQzNDoxMzQyM0EyOjE5NkJCRUI6NkIwMUVFMTMiLCJ2aXNpdG9yX2lkIjoiODUyNzAzOTE3ODYxMjAxMDUxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace27bf2ff090b31802dea9888072a8bdf98ceef6af4d7055a47a875294f2f4d1b
hovercard-subject-tagissue:5205528220
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/33893/issue_layout
twitter:imagehttps://opengraph.githubassets.com/74264fe0d9da8bbb7d63d0402d39f34758967261b5c6b62773b9d8e9ea9dc88c/angular/angular-cli/issues/33893
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/74264fe0d9da8bbb7d63d0402d39f34758967261b5c6b62773b9d8e9ea9dc88c/angular/angular-cli/issues/33893
og:image:altCommand build Description markTopLevelPure only runs in its aggressive mode for files under node_modules/@angular/. For every other package the safe mode is active, and in safe mode no top-level ca...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamehebus
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/angular/angular-cli git https://github.com/angular/angular-cli.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id36891867
octolytics-dimension-repository_nwoangular/angular-cli
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id36891867
octolytics-dimension-repository_network_root_nwoangular/angular-cli
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular-cli/issues/33893#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F33893
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular-cli%2Fissues%2F33893
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular-cli
Reloadhttps://github.com/angular/angular-cli/issues/33893
Reloadhttps://github.com/angular/angular-cli/issues/33893
Reloadhttps://github.com/angular/angular-cli/issues/33893
angularhttps://github.com/angular
angular-clihttps://github.com/angular/angular-cli
Codehttps://github.com/angular/angular-cli
Issues198 (198)https://github.com/angular/angular-cli/issues
Pull requests23 (23)https://github.com/angular/angular-cli/pulls
Actionshttps://github.com/angular/angular-cli/actions
Security and quality8 (8)https://github.com/angular/angular-cli/security
Insightshttps://github.com/angular/angular-cli/insights
https://github.com/angular/angular-cli
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/33893
New issuehttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/33893
Allow third-party packages declaring sideEffects: false to opt out of topLevelSafeModehttps://github.com/angular/angular-cli/issues/33893#top
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
gemini-triagedLabel noting that an issue has been triaged by geminihttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22gemini-triaged%22
needsTriagehttps://github.com/angular/angular-cli/milestone/11
https://github.com/hebus
hebushttps://github.com/hebus
on Aug 20, 2026https://github.com/angular/angular-cli/issues/33893#issue-5205528220
angular-robothttps://github.com/apps/angular-robot
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
gemini-triagedLabel noting that an issue has been triaged by geminihttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22gemini-triaged%22
on Aug 20, 2026https://github.com/angular/angular-cli/issues/33893#event-29755171442
angular-robothttps://github.com/apps/angular-robot
needsTriagehttps://github.com/angular/angular-cli/milestone/11
on Aug 20, 2026https://github.com/angular/angular-cli/issues/33893#event-29755173476
https://github.com/alan-agius4
alan-agius4https://github.com/alan-agius4
on Aug 21, 2026https://github.com/angular/angular-cli/issues/33893#issuecomment-5366264015
alan-agius4https://github.com/alan-agius4
not plannedhttps://github.com/angular/angular-cli/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Aug 21, 2026https://github.com/angular/angular-cli/issues/33893#event-29788152730
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Oct 19, 2026https://github.com/angular/angular-cli/issues/33893#issuecomment-6257053881
automatic conversation locking policyhttps://github.com/angular/angular/blob/f0fbced1c55bc8b8ed9df01cea99df42f3e7eae3/contributing-docs/auto-issue-locking.md
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Oct 19, 2026https://github.com/angular/angular-cli/issues/33893#event-33599993138
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular-cli/issues/33893
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular-cli/issues/33893
area: @angular/buildhttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22area%3A%20%40angular%2Fbuild%22
gemini-triagedLabel noting that an issue has been triaged by geminihttps://github.com/angular/angular-cli/issues?q=state%3Aopen%20label%3A%22gemini-triaged%22
needsTriageNo due datehttps://github.com/angular/angular-cli/milestone/11
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.