router_resource.ts is missing @__PURE__ on Symbol(), breaking tree-shaking of provideRouter() since 22.1.4 · Issue #70696 · angular/angular · GitHub
Skip to content

router_resource.ts is missing @__PURE__ on Symbol(), breaking tree-shaking of provideRouter() since 22.1.4 #70696

Description

@vitalii-hey

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

Yes

Description

We updated from Angular 22.0.5 to 22.1.6 and our initial bundle jumped from ~480 kB to ~555 kB, over the 500 kB CLI budget. We don't use router resources (withRouterResources()) anywhere in the app.

Bisected it patch by patch: 22.1.3 is fine (202 kB initial, just main+styles), 22.1.4 already has the jump (553 kB). So it's one of the router-resources commits that landed in 22.1.4 (cherry-picked from df83a340 and fa2aca96).

Traced it to provide_router.ts, which has a new top-level import:

import {createResourceOutletBindingEffects} from './router_resource';

That function is only used inside withRouterResources(), which is opt-in. But router_resource.ts itself has two module-level Symbol() calls with no @__PURE__ hint:

export const BLOCKING_SYMBOL: unique symbol = Symbol(
  typeof ngDevMode === 'undefined' || ngDevMode ? '__isBlocking' : '',
);
export const SOURCE_RESOURCE_SYMBOL: unique symbol = Symbol(
  typeof ngDevMode === 'undefined' || ngDevMode ? '__sourceResource' : '',
);

Without that hint esbuild treats the file as having a side effect and can't drop it, so the whole module (plus everything it pulls in — Router, effect, computed, resourceFromSnapshots, ...) ends up in the initial bundle. provide_router.ts is always eager since it's called from provideRouter(), so every app pays for this whether it uses router resources or not.

The fix looks pretty small — shared.ts in the same package already does this correctly for the same kind of symbol:

export const RouteTitleKey: unique symbol = /* @__PURE__ */ Symbol('RouteTitle');

so router_resource.ts just seems to be missing the same annotation on its two symbols.

Checked main too, the annotation is still missing there, so this isn't limited to the 22.1.x line.

Please provide a link to a minimal reproduction of the bug

No minimal repro repo, but it's easy to check: ng new a routed app, build it once pinned to 22.1.3 and once to 22.1.4 (core/cli/cdk/build all pinned), and compare the "Initial total" line from ng build. Neither build calls withRouterResources().

Please provide the exception or error you saw

No exception, just the CLI budget warning (bundle initial exceeded maximum budget).

Please provide the environment you discovered this bug in (run ng version)

Angular: 22.1.4, 22.1.5, 22.1.6 (all affected, verified by bisecting patch releases)
Node: 24.18.0

Anything else?

Confirmed the missing @__PURE__ is still absent on main, so this isn't limited to the 22.1.x line.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routergemini-triagedLabel noting that an issue has been triaged by gemini

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions