Visitar URL original
fix(compiler): ensure that partially compiled queries can handle forward references by petebacondarwin · Pull Request #44113 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20220105000634/https://github.com/angular/angular/pull/44113
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(compiler): ensure that partially compiled queries can handle forward references #44113

Conversation

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Nov 8, 2021 •

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. ViewQuery or ContentQuery) but its definition is later in the
file, then the reference must be wrapped in a forwardRef() call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in forwardRef()
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

Unfortunately, any libraries that were published before this gets merged will potentially have the problem going forward, if they have forwardRefs in their query definitions. The resolution it to simply build and release a new version. With that in mind, it might be worth landing this in 12.2.x LTS as well.

@google-cla google-cla bot added the cla: yes label Nov 8, 2021
@ngbot ngbot bot added this to the Backlog milestone Nov 8, 2021
@ngbot ngbot bot added this to the Backlog milestone Nov 8, 2021
@ngbot ngbot bot added this to the Backlog milestone Nov 8, 2021
@ngbot ngbot bot added this to the Backlog milestone Nov 8, 2021
@pullapprove pullapprove bot requested review from AndrewKushnir Nov 8, 2021
@petebacondarwin petebacondarwin force-pushed the linker-content-children-query-forward-ref-issue branch 3 times, most recently from 7b5e12c to 949fca5 Nov 8, 2021
@petebacondarwin petebacondarwin requested a review from JoostK Nov 8, 2021
This interface will be used in other situations so this change renames it to be more general as `MaybeForwardRefExpression`.
@petebacondarwin petebacondarwin force-pushed the linker-content-children-query-forward-ref-issue branch 2 times, most recently from 42c0b3d to 53a6df1 Nov 9, 2021
@petebacondarwin petebacondarwin force-pushed the linker-content-children-query-forward-ref-issue branch from 53a6df1 to 9b9d0de Nov 9, 2021
@petebacondarwin petebacondarwin requested review from JoostK and alxhub Nov 9, 2021
@petebacondarwin petebacondarwin force-pushed the linker-content-children-query-forward-ref-issue branch from 9b9d0de to e03badd Nov 9, 2021
@petebacondarwin petebacondarwin marked this pull request as draft Nov 9, 2021
@petebacondarwin petebacondarwin force-pushed the linker-content-children-query-forward-ref-issue branch from e03badd to 14b69b2 Nov 9, 2021
JoostK
JoostK approved these changes Nov 10, 2021
Copy link
Member

@JoostK JoostK left a comment

In general LGTM, but I'm deferring for a full-pass review to @alxhub.

packages/compiler/src/injectable_compiler_2.ts Outdated Show resolved Hide resolved
…ard references

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907
@petebacondarwin petebacondarwin force-pushed the linker-content-children-query-forward-ref-issue branch from f40e02c to c0ad276 Nov 10, 2021
alxhub
alxhub approved these changes Nov 10, 2021
@atscott
Copy link
Contributor

@atscott atscott commented Nov 10, 2021

@ngbot
Copy link

@ngbot ngbot bot commented Nov 10, 2021

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "ci/circleci: legacy-unit-tests-saucelabs" is failing
    pending 1 pending code review

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@atscott
Copy link
Contributor

@atscott atscott commented Nov 10, 2021

This PR was merged into the repository by commit 393efa5.

atscott added a commit that referenced this issue Nov 10, 2021
#44113)

This interface will be used in other situations so this change renames it to be more general as `MaybeForwardRefExpression`.

PR Close #44113
atscott added a commit that referenced this issue Nov 10, 2021
…ard references (#44113)

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

PR Close #44113
@atscott atscott closed this in 67fbec3 Nov 10, 2021
atscott added a commit that referenced this issue Nov 10, 2021
…ard references (#44113)

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

PR Close #44113
devversion added a commit to devversion/material2 that referenced this issue Nov 11, 2021
…lation output

We updated to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: angular#23882. That
should help ensuring JIT linking does not regress.

Fixes angular#23907.
devversion added a commit to devversion/material2 that referenced this issue Nov 11, 2021
…lation output

Updates to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: angular#23882. That
should help ensuring JIT linking does not regress.

Fixes angular#23907.
amysorto pushed a commit to angular/components that referenced this issue Nov 11, 2021
…lation output (#23951)

Updates to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: #23882. That
should help ensuring JIT linking does not regress.

Fixes #23907.
amysorto added a commit to angular/components that referenced this issue Nov 11, 2021
…lation output (#23951)

Updates to Angular v13.0.1 which fixes the partial compilation output
for `forwardRef` usages in queries. The fixed partial compilation output
will ensure that Angular CDK/Material works with JIT linking at runtime,
as done in e.g. Jest.

Fix upstream: angular/angular#44113.

We will add some testing for the JIT linker to the `angular/components`
repository with: #23882. That
should help ensuring JIT linking does not regress.

Fixes #23907.

(cherry picked from commit 8cb0f12)
@petebacondarwin petebacondarwin deleted the linker-content-children-query-forward-ref-issue branch Nov 12, 2021
crisbeto added a commit to crisbeto/material.angular.io that referenced this issue Nov 19, 2021
We're currently locked into version 13.0.0 which has a problem with queries using `forwardRef` which affects several places in the docs like the navigation between docs and API examples.

These changes update to 13.0.1 which contains angular/angular#44113 in order to resolve the issue.
crisbeto added a commit to angular/material.angular.io that referenced this issue Nov 19, 2021
We're currently locked into version 13.0.0 which has a problem with queries using `forwardRef` which affects several places in the docs like the navigation between docs and API examples.

These changes update to 13.0.1 which contains angular/angular#44113 in order to resolve the issue.
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Dec 13, 2021

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 Dec 13, 2021
dimakuba added a commit to dimakuba/angular that referenced this issue Dec 28, 2021
angular#44113)

This interface will be used in other situations so this change renames it to be more general as `MaybeForwardRefExpression`.

PR Close angular#44113
dimakuba added a commit to dimakuba/angular that referenced this issue Dec 28, 2021
…ard references (angular#44113)

When a partially compiled component or directive is "linked" in JIT mode, the body
of its declaration is evaluated by the JavaScript runtime. If a class is referenced
in a query (e.g. `ViewQuery` or `ContentQuery`) but its definition is later in the
file, then the reference must be wrapped in a `forwardRef()` call.

Previously, query predicates were not wrapped correctly in partial declarations
causing the code to crash at runtime. In AOT mode, this code is never evaluated
but instead transformed as part of the build, so this bug did not become apparent
until Angular Material started running JIT mode tests on its distributable output.

This change fixes this problem by noting when queries are wrapped in `forwardRef()`
calls and ensuring that this gets passed through to partial compilation declarations
and then suitably stripped during linking.

See angular/components#23882 and angular/components#23907

PR Close angular#44113
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants