Skip to content

After upgrading to RC2, links under defer blocks with control statement e.g. @if takes 2 clicks to navigate #58690

Closed

Description

@naveedahmed1

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

core

Is this a regression?

Yes

Description

After upgrading to RC2, links under defer blocks with control statement e.g. @if now takes 2 clicks to navigate

For the below code its now taking two clicks for the actual navigation to complete.

The first click hydrates this code and removes ngb="d9" attribute from the anchor tag and then clicking it again actully takes the user to the next page.

@defer(on idle; hydrate on interaction) {
<div class="mat-chip-list layout-row layout-wrap layoutalign-center-center pl10 pr10 mb20">

  @for (item of topCities(); track item.name; let index = $index) {
  <a [routerLink]="['/jobs/',urlCountry(),item.url]" class="mat-chip">Jobs in {{item.name}}</a>
  }

  @if (telecommute()) {

  <a [routerLink]="['/jobs/',urlCountry(),'online']" class="mat-chip">Online Jobs</a>

  }

  <a [routerLink]="['/jobs/',urlCountry()]" title="Jobs in {{country()}}" class="mat-chip">Jobs in {{_gs.country()}}</a>

</div>
}

On the otherhand the below code seems to be working as expected:

@defer(on idle; prefetch on immediate; hydrate on interaction) {
<div class="text-center mt30 mb30 pt5 pb5">
    <a ripple [routerLink]="isBrowser() ? null : '/account/register'" (click)="login('/account/dashboard')" rel="nofollow" class="signup-button">Start Your Job Search – Join Now!</a>
</div>
}

You can try this on the reproduction repo I shared below.

  • Clone the repo
  • Run ng serve
  • Click any link from the top nav and you will notice that the first click hydrates the component and then the second click actully take you to the next page

If you remove the if condition (https://github.com/naveedahmed1/incremental-hydration-demo/blob/54f41384ec5aa01e70ab2127f1b83015580185d1/src/app/app.component.html#L5) it will work just fine.

Please provide a link to a minimal reproduction of the bug

https://github.com/naveedahmed1/incremental-hydration-demo

Please provide the exception or error you saw

Links under defer blocks with control statement e.g. @if takes 2 clicks to navigate

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

Angular CLI: 19.0.0-rc.2
Node: 20.12.2
Package Manager: npm 10.6.0
OS: win32 x64

Angular: 19.0.0-rc.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router, ssr

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1900.0-rc.2
@angular-devkit/build-angular   19.0.0-rc.2
@angular-devkit/core            19.0.0-rc.2
@angular-devkit/schematics      19.0.0-rc.2
@schematics/angular             19.0.0-rc.2
rxjs                            7.8.1
typescript                      5.6.3
zone.js                         0.15.0

Anything else?

No response

Activity

  1. naveedahmed1 commented on Nov 15, 2024

    @naveedahmed1
    ContributorAuthor
  2. added
    area: core
    on Nov 15, 2024
  3. added this to the needsTriage milestone on Nov 15, 2024
  4. thePunderWoman commented on Nov 15, 2024

    @thePunderWoman
    Contributor

    @naveedahmed1 I've replicated this. It affects routerLinks constructed via arrays or if using data from the parent component.

  5. naveedahmed1 commented on Nov 16, 2024

    @naveedahmed1
    ContributorAuthor

    Are you sure? For the below code, the first Login link is taking two clicks whereas the second login link is working just fine:

          @if (isLoggedIn()) {
          <li>
            <a routerLink="/account/dashboard">Dashboard</a>
          </li>
          } @else {
          <li >
            <a routerLink="{{isBrowser() ? null : '/account/login'}}" (click)="login(successfulLoginRedirectURL())">Login</a>
          </li>
          }
    
          <li>
            <a routerLink="{{isBrowser() ? null : '/account/login'}}" (click)="login(successfulLoginRedirectURL())">Login</a>
          </li>
    

    and even routerLink with array is also working fine if I move it outide of the if block i.e:

          <li >
            <a [routerLink]="isBrowser() ? null : '/account/login'">Login</a>
          </li>
    
  6. thePunderWoman commented on Nov 18, 2024

    @thePunderWoman
    Contributor

    @naveedahmed1 It's really any routerLink that's not a pure string. We're working on it.

  7. added a commit that references this issue on Nov 21, 2024
    bd08d1d
  8. angular-automatic-lock-bot commented on Dec 22, 2024

    @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 Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: corecore: incremental hydration

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions