Thanks to visit codestin.com
Credit goes to github.com

Skip to content

HMR-related fixes #59644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

HMR-related fixes #59644

wants to merge 4 commits into from

Conversation

crisbeto
Copy link
Member

Includes the following HMR-related fixes:

fix(core): replace metadata in place during HMR

Currently during HMR we swap out the entire module definition (e.g. MyComp.ɵcmp = newDef). In standalone components and most module-based ones this works fine, however in some cases (e.g. circular dependencies) the compiler can produce a setComponentScope call for a module-based component. This call doesn't make it into the HMR replacement function, because it is defined in the module's file, not the component's. As a result, the dependencies of these components are cleared out upon replacement.

A secondary problem is that the directiveDefs and pipeDefs fields can save references to definitions that later become stale as a result of HMR.

These changes resolve both issues by:

  1. Performing the replacement by copying the properties from the new definition onto the old one, while keeping it in place.
  2. Preserving the initial directiveDefs, pipeDefs and setInput.

fix(core): capture self-referencing component during HMR

Fixes that we were filtering out the component itself from the set of dependencies when HMR is enabled, breaking self-referencing components.

fix(platform-browser): clear renderer cache during HMR when using async animations

Fixes that the async animations renderer didn't have the logic to clean up its style cache during HMR. This is identical to #59393.

fix(compiler-cli): extract parenthesized dependencies during HMR

Fixes that the HMR dependency extraction logic wasn't accounting for parenthesized identifiers correctly.

Fixes #59640.
Fixes #59632.
Fixes #59639.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Jan 21, 2025
@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime labels Jan 21, 2025
@ngbot ngbot bot added this to the Backlog milestone Jan 21, 2025
@crisbeto crisbeto marked this pull request as ready for review January 21, 2025 10:22
Currently during HMR we swap out the entire module definition (e.g. `MyComp.ɵcmp = newDef`). In standalone components and most module-based ones this works fine, however in some cases (e.g. circular dependencies) the compiler can produce a `setComponentScope` call for a module-based component. This call doesn't make it into the HMR replacement function, because it is defined in the module's file, not the component's. As a result, the dependencies of these components are cleared out upon replacement.

A secondary problem is that the `directiveDefs` and `pipeDefs` fields can save references to definitions that later become stale as a result of HMR.

These changes resolve both issues by:
1. Performing the replacement by copying the properties from the new definition onto the old one, while keeping it in place.
2. Preserving the initial `directiveDefs`, `pipeDefs` and `setInput`.

Fixes angular#59639.
Fixes that we were filtering out the component itself from the set of dependencies when HMR is enabled, breaking self-referencing components.

Fixes angular#59632.
…nc animations

Fixes that the async animations renderer didn't have the logic to clean up its style cache during HMR. This is identical to angular#59393.

Fixes angular#59640.
Fixes that the HMR dependency extraction logic wasn't accounting for parenthesized identifiers correctly.
@AndrewKushnir AndrewKushnir removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Jan 21, 2025
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Jan 21, 2025
@crisbeto
Copy link
Member Author

Caretaker note: this is ready to go. For some reason the CI is showing that one review is pending.

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 67be7d2.

The changes were merged into the following branches: main, 19.1.x

AndrewKushnir pushed a commit that referenced this pull request Jan 21, 2025
Fixes that we were filtering out the component itself from the set of dependencies when HMR is enabled, breaking self-referencing components.

Fixes #59632.

PR Close #59644
AndrewKushnir pushed a commit that referenced this pull request Jan 21, 2025
…nc animations (#59644)

Fixes that the async animations renderer didn't have the logic to clean up its style cache during HMR. This is identical to #59393.

Fixes #59640.

PR Close #59644
AndrewKushnir pushed a commit that referenced this pull request Jan 21, 2025
)

Fixes that the HMR dependency extraction logic wasn't accounting for parenthesized identifiers correctly.

PR Close #59644
AndrewKushnir pushed a commit that referenced this pull request Jan 21, 2025
Currently during HMR we swap out the entire module definition (e.g. `MyComp.ɵcmp = newDef`). In standalone components and most module-based ones this works fine, however in some cases (e.g. circular dependencies) the compiler can produce a `setComponentScope` call for a module-based component. This call doesn't make it into the HMR replacement function, because it is defined in the module's file, not the component's. As a result, the dependencies of these components are cleared out upon replacement.

A secondary problem is that the `directiveDefs` and `pipeDefs` fields can save references to definitions that later become stale as a result of HMR.

These changes resolve both issues by:
1. Performing the replacement by copying the properties from the new definition onto the old one, while keeping it in place.
2. Preserving the initial `directiveDefs`, `pipeDefs` and `setInput`.

Fixes #59639.

PR Close #59644
AndrewKushnir pushed a commit that referenced this pull request Jan 21, 2025
Fixes that we were filtering out the component itself from the set of dependencies when HMR is enabled, breaking self-referencing components.

Fixes #59632.

PR Close #59644
AndrewKushnir pushed a commit that referenced this pull request Jan 21, 2025
…nc animations (#59644)

Fixes that the async animations renderer didn't have the logic to clean up its style cache during HMR. This is identical to #59393.

Fixes #59640.

PR Close #59644
AndrewKushnir pushed a commit that referenced this pull request Jan 21, 2025
)

Fixes that the HMR dependency extraction logic wasn't accounting for parenthesized identifiers correctly.

PR Close #59644
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
Currently during HMR we swap out the entire module definition (e.g. `MyComp.ɵcmp = newDef`). In standalone components and most module-based ones this works fine, however in some cases (e.g. circular dependencies) the compiler can produce a `setComponentScope` call for a module-based component. This call doesn't make it into the HMR replacement function, because it is defined in the module's file, not the component's. As a result, the dependencies of these components are cleared out upon replacement.

A secondary problem is that the `directiveDefs` and `pipeDefs` fields can save references to definitions that later become stale as a result of HMR.

These changes resolve both issues by:
1. Performing the replacement by copying the properties from the new definition onto the old one, while keeping it in place.
2. Preserving the initial `directiveDefs`, `pipeDefs` and `setInput`.

Fixes angular#59639.

PR Close angular#59644
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
Fixes that we were filtering out the component itself from the set of dependencies when HMR is enabled, breaking self-referencing components.

Fixes angular#59632.

PR Close angular#59644
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
…nc animations (angular#59644)

Fixes that the async animations renderer didn't have the logic to clean up its style cache during HMR. This is identical to angular#59393.

Fixes angular#59640.

PR Close angular#59644
PrajaktaB27 pushed a commit to PrajaktaB27/angular that referenced this pull request Feb 7, 2025
…ular#59644)

Fixes that the HMR dependency extraction logic wasn't accounting for parenthesized identifiers correctly.

PR Close angular#59644
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release
Projects
None yet
3 participants