Skip to content

HMR broken with dynamic component providers #59634

Closed

Description

@mattlewis92

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

compiler

Is this a regression?

Yes

Description

When trying out the new component HMR we ran into a couple issues when using dynamic component providers

For example:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  providers: [isDevelopmentMode ? DirectiveTimingService : []],
  standalone: false,
})
export class AppComponent {}

Throws app.component.ts:108 ReferenceError: DirectiveTimingService is not defined at runtime:

Image

Not sure if this is the same or a different issue, but declaring a provider with useFactory and deps also throws an error

@Component({
  selector: 'cu-prompt-template-empty-description',
  templateUrl: './prompt-template-empty-description.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
  providers: [
    {
      provide: DropdownListKeyboardController,
      useFactory: (
        parentInjector: Injector,
        dropdownListKeyboardController?: DropdownListKeyboardController,
      ) => {
        if (!dropdownListKeyboardController) {
          const injector = Injector.create({
            providers: [{ provide: DropdownListKeyboardController }],
            parent: parentInjector,
          });
          dropdownListKeyboardController = injector.get(
            DropdownListKeyboardController,
          );
        }

        return dropdownListKeyboardController;
      },
      deps: [
        Injector,
        [new Optional(), new SkipSelf(), DropdownListKeyboardController],
      ],
    },
  ],
  standalone: false,
})
export class PromptTemplateEmptyDescriptionComponent {}

Will throw ReferenceError: Optional is not defined:

Image

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Please let me know if the information above isn't sufficient to create a test case!

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

Angular: 19.1.2
... animations, common, compiler, compiler-cli, core, elements
... forms, language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1901.3
@angular-devkit/build-angular   19.1.3
@angular-devkit/core            19.1.3
@angular-devkit/schematics      19.1.3
@angular/build                  19.1.3
@angular/cdk                    18.2.2
@angular/google-maps            15.2.9
@schematics/angular             19.1.3
ng-packagr                      19.0.1
rxjs                            7.8.0
typescript                      5.6.3
webpack                         5.96.1
zone.js                         0.14.4

Anything else?

No response

Activity

  1. added
    area: core
    on Jan 20, 2025
  2. modified the milestone: needsTriage on Jan 20, 2025
  3. clydin commented on Jan 21, 2025

    @clydin
    Member

    Addressed via #59637

  4. angular-automatic-lock-bot commented on Feb 21, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Feb 21, 2025
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: corecore: hot module replacement (HMR)state: has PR

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions