Skip to content
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

fix(core): deduplicate imports of standalone components in JIT compiler #46439

Closed
wants to merge 1 commit into from

Conversation

JoostK
Copy link
Member

@JoostK JoostK commented Jun 20, 2022

During JIT compilation of standalone components the compiler did not deduplicate
declarations in the imports array, unlike the AOT compiler. This may result in
runtime errors during directive matching, when the same component is found
multiple times resulting in NG0300, for example:

NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField.

This commit fixes the issue by deduplicating imports in the JIT compiler.

Relates to #46109 (comment)

Closes #46109

@JoostK JoostK added area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler compiler: jit cross-cutting: standalone Issues related to the NgModule-less world labels Jun 20, 2022
@ngbot ngbot bot modified the milestone: Backlog Jun 20, 2022
@JoostK JoostK marked this pull request as ready for review June 20, 2022 20:02
@JoostK JoostK added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 20, 2022
@pullapprove pullapprove bot requested a review from atscott June 20, 2022 20:02
@JoostK JoostK requested review from pkozlowski-opensource and removed request for atscott June 20, 2022 20:02
@@ -246,16 +246,23 @@ function getStandaloneDefFunctions(type: Type<any>, imports: Type<any>[]): {
// Standalone components are always able to self-reference, so include the component's own
// definition in its `directiveDefs`.
cachedDirectiveDefs = [getComponentDef(type)!];
const seen = new Set<Type<any>>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: any => unknown?

@@ -453,6 +453,42 @@ describe('standalone components, directives and pipes', () => {
expect(fixture.nativeElement.innerHTML).toBe('<div red="true">blue</div>');
});

it('should deduplicate declarations', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking of a test scenario to verify de-duped pipes but nothing comes to my mind (short of explicitly asserting on a def...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was pondering the same; decided to keep as is as inspecting the pipe defs seems overkill and there won't be a behavior difference (but it felt incorrect not to deduplicate pipes)

Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pkozlowski-opensource pkozlowski-opensource added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 21, 2022
During JIT compilation of standalone components the compiler did not deduplicate
declarations in the imports array, unlike the AOT compiler. This may result in
runtime errors during directive matching, when the same component is found
multiple times resulting in NG0300, for example:

> NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField.

This commit fixes the issue by deduplicating imports in the JIT compiler.

Relates to angular#46109 (comment)

Closes angular#46109
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JoostK JoostK added the action: presubmit The PR is in need of a google3 presubmit label Jun 21, 2022
@AndrewKushnir
Copy link
Contributor

Presubmit.

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Jun 21, 2022
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit ddd6d66.

AndrewKushnir pushed a commit that referenced this pull request Jun 21, 2022
…er (#46439)

During JIT compilation of standalone components the compiler did not deduplicate
declarations in the imports array, unlike the AOT compiler. This may result in
runtime errors during directive matching, when the same component is found
multiple times resulting in NG0300, for example:

> NG0300: Multiple components match node with tagname mat-form-field: MatFormField and MatFormField.

This commit fixes the issue by deduplicating imports in the JIT compiler.

Relates to #46109 (comment)

Closes #46109

PR Close #46439
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Jun 28, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/animations](https://github.com/angular/angular) | dependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fanimations/14.0.2/14.0.3) |
| [@angular/common](https://github.com/angular/angular) | dependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fcommon/14.0.2/14.0.3) |
| [@angular/compiler](https://github.com/angular/angular) | dependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/14.0.2/14.0.3) |
| [@angular/compiler-cli](https://github.com/angular/angular) | devDependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/14.0.2/14.0.3) |
| [@angular/core](https://github.com/angular/angular) | dependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fcore/14.0.2/14.0.3) |
| [@angular/forms](https://github.com/angular/angular) | dependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fforms/14.0.2/14.0.3) |
| [@angular/platform-browser](https://github.com/angular/angular) | dependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/14.0.2/14.0.3) |
| [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | patch | [`14.0.2` -> `14.0.3`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/14.0.2/14.0.3) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v14.0.3`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1403-2022-06-22)

[Compare Source](angular/angular@14.0.2...14.0.3)

##### animations

| Commit | Type | Description |
| -- | -- | -- |
| [3dd7bb3f8f](angular/angular@3dd7bb3) | fix | reset the start and done fns on player reset ([#&#8203;46364](angular/angular#46364)) |

##### core

| Commit | Type | Description |
| -- | -- | -- |
| [c086653655](angular/angular@c086653) | fix | deduplicate imports of standalone components in JIT compiler ([#&#8203;46439](angular/angular#46439)) |
| [5d3b97e1f8](angular/angular@5d3b97e) | fix | handle NgModules with standalone pipes in TestBed correctly ([#&#8203;46407](angular/angular#46407)) |

##### platform-server

| Commit | Type | Description |
| -- | -- | -- |
| [6ad7b40a6f](angular/angular@6ad7b40) | fix | invalid style attribute being generated for null values ([#&#8203;46433](angular/angular#46433)) |

#### Special Thanks

4javier, Aakash, Alan Agius, Andrew Kushnir, Aristeidis Bampakos, Dany Paredes, Derek Cormier, JoostK, Kristiyan Kostadinov, Paul Gschwendtner, Ramesh Thiruchelvam, behrooz bozorg chami, dario-piotrowicz, markostanimirovic, renovate\[bot] and web-dave

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1431
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@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 Jul 22, 2022
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 compiler: jit cross-cutting: standalone Issues related to the NgModule-less world target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unintended duplicate imports can cause rendering error in standalone component life cycle.
3 participants