Skip to content

cdk/overlay: providing OVERLAY_DEFAULT_CONFIG pulls the whole overlay implementation into the initial bundle #34171

Done

Description

@zengqinglei

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

cdk

Is this a regression?

No

Description

The documented way to globally disable the popover behaviour is to provide OVERLAY_DEFAULT_CONFIG at bootstrap (see overlay.md). In 22.3.0, OVERLAY_DEFAULT_CONFIG is declared in fesm2022/_overlay-module-chunk.mjs together with Overlay, createOverlayRef, position/scroll strategies and the portal/scrolling imports. Importing only the token from @angular/cdk/overlay in an application config therefore keeps that implementation in the initial bundle even when every overlay consumer is lazy-loaded.

UI kits such as Spartan (provideSpartanHlm()) do exactly this, so every app using them pays for the overlay code at startup.

Measured on an Angular 22.3 application builder project (esbuild, production): removing the single root provider { provide: OVERLAY_DEFAULT_CONFIG, useValue: { usePopover: false } } reduced the initial bundle from 616.45 kB to 567.21 kB raw (−49.24 kB; about −11 kB transfer). After removal only ~3.6 kB of CDK code remained in main.

Because Overlay/Dialog are root services that read the token through their own injector, the token cannot simply be moved to a lazy route provider.

Proposed solution

Declare OVERLAY_DEFAULT_CONFIG (and similar configuration tokens) in a small side-effect-free module that does not import the overlay implementation, re-exported from @angular/cdk/overlay as today — in line with the "lightweight injection tokens" guidance on angular.dev.

Minimal reproduction

  1. ng new repro --style css (Angular 22.3), add @angular/cdk@22.3.0.
  2. In app.config.ts add { provide: OVERLAY_DEFAULT_CONFIG, useValue: { usePopover: false } } (import from @angular/cdk/overlay); do not use any overlay in the app.
  3. ng build --stats-json and compare the initial total / inspect browser-stats.json with and without the provider.

Activity

  1. crisbeto commented on Nov 27, 2026

    @crisbeto
    Member

    Moving it into a separate entrypoint would be a breaking change and re-exporting defeats the purpose of moving it in the first place.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions