Skip to content

fix: 🐛 ng g @angular/core:control-flow schematic makes a lot of mistakes #52927

Closed

Description

@bjornharvold

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

core

Is this a regression?

No

Description

Dear Team Angular 🦸‍♂️

Changing to control flow was the last step of our Angular 17 migration journey. It took us 2 days to migrate over to the "standalone way of doing things" in our 2000+ monorepo.

Once we ran the last schematic to introduce control flow, it changed 730 html files and the build failed.

We took a look at why it was failing. Attaching a zip ball that contains an advanced page and what it looked like before and after we applied the schematic. I recommend opening the files up with a diff tool.

Archive.zip

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Look at the errors in the attached zip.

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

Node   : 20.9.0
   OS     : darwin-arm64
   yarn   : 1.22.19
   @angular/core      : 17.0.2
   nx                 : 17.1.1
   @nx/js             : 17.1.1
   @nx/jest           : 17.1.1
   @nx/linter         : 17.1.1
   @nx/eslint         : 17.1.1
   @nx/workspace      : 17.1.1
   @nx/angular        : 17.1.1
   @nx/cypress        : 17.1.1
   @nx/devkit         : 17.1.1
   @nx/eslint-plugin  : 17.1.1
   @nx/storybook      : 17.1.1
   @nrwl/tao          : 17.1.1
   @nx/web            : 17.1.1
   @nx/webpack        : 17.1.1
   typescript         : 5.2.2
   ---------------------------------------
   Community plugins:
   @compodoc/compodoc               : 1.1.22
   @fortawesome/angular-fontawesome : 0.14.0
   @jscutlery/semver                : 4.0.0
   @ng-bootstrap/ng-bootstrap       : 15.1.2
   @ngneat/transloco                : 6.0.0
   @ngrx/component                  : 16.3.0
   @ngrx/component-store            : 16.3.0
   @ngrx/data                       : 16.3.0
   @ngrx/effects                    : 16.3.0
   @ngrx/entity                     : 16.3.0
   @ngrx/router-store               : 16.3.0
   @ngrx/schematics                 : 16.3.0
   @ngrx/store                      : 16.3.0
   @ngrx/store-devtools             : 16.3.0
   @storybook/angular               : 7.5.3
   angular-calendar                 : 0.31.0

Anything else?

No response

Activity

  1. added
    area: migrations
    core: control flow
    on Nov 15, 2023
  2. added this to the needsTriage milestone on Nov 15, 2023
  3. jessicajaniuk commented on Nov 15, 2023

    @jessicajaniuk
    Contributor

    @bjornharvold I appreciate the report, but can you upload your migrated templates to a github repo for us to look at? A zip file is not safe for us to open. We're also about to release our new patch version, which will have updated fixes. So it's likely issues may have been resolved already.

  4. jessicajaniuk commented on Nov 15, 2023

    @jessicajaniuk
    Contributor

    17.0.3 is out now, which included some migration fixes. Let us know if you're still seeing issues. Ideally provide minimal reproductions for us to work with.

  5. bjornharvold commented on Nov 16, 2023

    @bjornharvold
    Author

    Hi @jessicajaniuk

    Having the same issues. Not sure how a minimal reproduction would help. I would create a new project and put the html file I already shared with you in app.component.html and you would run the migration schematic which would produce the after.txt file I also shared with you.

    I think more interestingly is to look at the files I shared in a diff viewer to make out in which cases the schematic fails.

    Here's the result after I upgraded to 17.0.3 and ran the schematic on the previous before.txt I already shared. It's clear the schematic gets confused with multi-line elements for example.

    FYI My entire project uses the default prettier setting of 80 character print width and I would assume many other projects do this too.

    after-17.0.3.txt

    Cheers,
    Bjorn

  6. jessicajaniuk commented on Nov 16, 2023

    @jessicajaniuk
    Contributor

    @bjornharvold Hi Bjorn. I know you sent us a big zip file, but for security reasons we are not allowed to open zip files. The minimal reproduction is intended to help us isolate the migrated issues. You can use gist, stackblitz, and or a github repository to upload src files. You can even use a comment with 3 backticks to share code snippets. For example:

    // code goes here
    <div></div>
    
  7. bjornharvold commented on Nov 17, 2023

    @bjornharvold
    Author

    Ah, I see. I didn't know. I first tried pasting it here but the component is way too large.

    Here's a gist of the diff between before and after:
    https://gist.github.com/bjornharvold/fa713051c0f87caf46bc9bdddddbfd53

  8. jessicajaniuk commented on Nov 17, 2023

    @jessicajaniuk
    Contributor

    @bjornharvold Thank you! I'll take a look.

  9. jessicajaniuk commented on Nov 17, 2023

    @jessicajaniuk
    Contributor

    @bjornharvold OK, I can tell some of the issues you're seeing are pre-17.0.3 in this example due to presence of placeholder strings (like #showLoadingIndicator| in the first example) that have since been resolved. I've also added individual test cases for some of the ng-container diffs you're seeing here and they do pass. So, the suspicion I have is that your template is just so large that the offset is off by one somewhere, which gets worse as it moves down the file. Without the full original template to run, it'll be harder for me to debug. Can you create a gist of the pre-transformed template? I can try running it through here and that'll help me isolate where that offset shift is happening.

  10. jessicajaniuk commented on Nov 17, 2023

    @jessicajaniuk
    Contributor

    @bjornharvold I was incorrect! I've been able to replicate the problem locally. It looks like it's specifically an issue with if then else usages. Your template migrates perfectly without the then clause at the start. That's a bug I can definitely fix. Thanks for reporting this! I will have a fix out shortly.

  11. marcusrettig commented on Nov 17, 2023

    @marcusrettig

    We had an issue with nested [ngSwitch] cases, e.g.

    <div [ngSwitch]="mimeTypeCategory">
      <div *ngSwitchCase="'text'" [ngSwitch]="mimeTypeExtension">
        <img *ngSwitchCase="'plain'" src="/assets/file-types/TXT.svg" alt="TXT icon" />
        <!-- ... -->
        <img *ngSwitchDefault src="/assets/file-types/Empty.svg" alt="File icon" />
      </div>
      <!-- ... -->
      <img *ngSwitchDefault src="/assets/file-types/Empty.svg" alt="File icon" />
    </div>

    produces the following output

    <div>
    @switch (mimeTypeCategory) {
      @case ('text') {
      <div [ 
    @switch (mimeTypeExtension) {   <i@case ('plain') {
      mg *rc="/assets/file-types/TXT.svg" alt="TXT icon" />
     
    }   <!-- ... -->
        <i@default {
      mg *rc="/assets/file-types/Empty.svg" alt="File icon" />
     
    } </}
    div>
    }
      <!-- ... -->
      @default {
      <img src="/assets/file-types/Empty.svg" alt="File icon" />
    }
    }
    </div>

    Other than that, version 17.0.3 worked very well for most of our code.

  12. jessicajaniuk commented on Nov 17, 2023

    @jessicajaniuk
    Contributor

    @marcusrettig Can you file a separate bug for that one? That'd be helpful for tracking purposes.

    UPDATE: I created #53009 to track it. Thanks!

  13. jessicajaniuk commented on Nov 17, 2023

    @jessicajaniuk
    Contributor

    @bjornharvold #53006 fixes this issue. Thanks again for reporting it!

  14. added a commit that references this issue on Nov 17, 2023
    0485fe2
  15. bjornharvold commented on Nov 18, 2023

    @bjornharvold
    Author

    Thanks for the super fast response here @jessicajaniuk

  16. added a commit that references this issue on Nov 20, 2023
    13bf5b7
  17. bjornharvold commented on Nov 21, 2023

    @bjornharvold
    Author

    I can confirm that that v17.0.4 fixes all past issues. Thank you. It asked if I wanted to format my code and I initially said yes. This made me wait for 10 hours without anything happening even though node was at 100% CPU the whole time. So I started over again and declined the formatting and that worked without issues. Ran the code through prettier manually instead. Will not create a ticket for the wait time. My Angular 17 migration is officially complete 🍿🍺

  18. jessicajaniuk commented on Nov 21, 2023

    @jessicajaniuk
    Contributor

    Thanks for the heads up on the formatting. I'll keep an eye on that process.

  19. angular-automatic-lock-bot commented on Dec 22, 2023

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

  20. locked and limited conversation to collaborators on Dec 22, 2023
  21. added a commit that references this issue on Jan 23, 2024
    9624924
  22. added 2 commits that reference this issue on Jan 26, 2024
    5564d02
    b2c9431
  23. added a commit that references this issue on Jan 26, 2024
    8661e10
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: migrationscore: control flow

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions