Skip to content

ivy: accessing undefined ViewChild properly with elvis operator in template breaks #34087

Closed

Description

@mattlewis92

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Yes, works fine in v8

Description

If I add a ViewChild decorator to an undefined component in a template and try and access it using the elvis operator in a template then the expression breaks and nothing is outputted in the template.

🔬 Minimal Reproduction

https://github.com/mattlewis92/ivy-view-child-accesssor-bug/blob/master/src/app/app.component.html#L1

Where foo is:
https://github.com/mattlewis92/ivy-view-child-accesssor-bug/blob/master/src/app/app.component.ts#L11

🔥 Exception or Error

There is no error, it fails silently to render:
Screenshot 2019-11-27 at 15 50 48

🌍 Your Environment

Angular Version:


Angular CLI: 9.0.0-rc.3
Node: 12.10.0
OS: darwin x64
Angular: 9.0.0-rc.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.0-rc.3
@angular-devkit/build-angular     0.900.0-rc.3
@angular-devkit/build-optimizer   0.900.0-rc.3
@angular-devkit/build-webpack     0.900.0-rc.3
@angular-devkit/core              9.0.0-rc.3
@angular-devkit/schematics        9.0.0-rc.3
@ngtools/webpack                  9.0.0-rc.3
@schematics/angular               9.0.0-rc.3
@schematics/update                0.900.0-rc.3
rxjs                              6.5.3
typescript                        3.6.4
webpack                           4.41.2

Anything else relevant?
Nope

Activity

  1. modified the milestone: needsTriage on Nov 27, 2019
  2. modified the milestones: needsTriage, v9-blockers on Dec 3, 2019
  3. AndrewKushnir commented on Dec 4, 2019

    @AndrewKushnir
    Contributor

    Hi @mattlewis92, thanks for reporting this issue.

    I performed the investigation and found out that the code generated by Ivy Compiler in a template function looks correct (compiled locally):

      textInterpolate1('This doesn\'t work: ',(((ctx.foo == null)? null: ctx.foo.bar)? 'bar': 'bam'),'');
    

    and it looks like parentheses are removed after further processing (presumably in CLI):

      _angular_core__WEBPACK_IMPORTED_MODULE_0__["ɵɵtextInterpolate1"]("This doesn't work: ", ctx.foo == null ? null : ctx.foo.bar ? "bar" : "bam", " ");
    

    Which changes the logic and makes the code return null (and render nothing) instead of rendering 'bam' string.

    @filipesilva do you know if this is an optimization step in CLI that might affect this?

  4. AndrewKushnir commented on Dec 4, 2019

    @AndrewKushnir
    Contributor

    FYI @alxhub performed further investigation and fixed the problem in PR #34221 👍
    The problem was that I looked at the JIT output and the problem was present in AOT output (which is now aligned with JIT).
    Thank you.

  5. mattlewis92 commented on Dec 4, 2019

    @mattlewis92
    ContributorAuthor

    Amazing, thank you for looking into it so quickly! ❤️

  6. added a commit that references this issue on Dec 4, 2019
    025bf0d
  7. added a commit that references this issue on Dec 6, 2019
    af36bc6
  8. angular-automatic-lock-bot commented on Jan 6, 2020

    @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.

  9. locked and limited conversation to collaborators on Jan 6, 2020
  10. added
    regressionIndicates than the issue relates to something that worked in a previous version
    and removed on Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compilerIssues related to `ngc`, Angular's template compilerregressionIndicates than the issue relates to something that worked in a previous versionstate: has PRtype: bug/fix

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions