Skip to content

Incremental Hydration throws error - Cannot read properties of undefined (reading 'p') on Client Side Navigation to this page #58359

Closed

Description

@naveedahmed1

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

core

Is this a regression?

No

Description

When using Incremental Hydration, the below code works but subsequent code throws error on client side navigation to this page from another page:

This works:

@if (pageHeading() && !isLoggedIn()) {
@defer(hydrate when isLoggedIn()) {
<div class="mat-card p15 pb7 mb10">
  <h1 class="mb10">{{pageHeading()}}</h1>
  <p class="mb10 paragraph">{{pageDescription()}}</p>
</div>
}
}

This doesn't work:

@defer(hydrate when isLoggedIn()) {
@if (pageHeading() && !isLoggedIn()) {
<div class="mat-card p15 pb7 mb10">
  <h1 class="mb10">{{pageHeading()}}</h1>
  <p class="mb10 paragraph">{{pageDescription()}}</p>
</div>
}
}

Error

core.mjs:7283 ERROR TypeError: Cannot read properties of undefined (reading 'p')
    at findFirstKnownParentDeferBlock (core.mjs:22378:54)
    at core.mjs:22414:7
    at Generator.next (<anonymous>)
    at chunk-4MWRP73S.js?v=7a14075d:76:61
    at new ZoneAwarePromise (zone.js:2702:25)
    at __async (chunk-4MWRP73S.js?v=7a14075d:60:10)
    at hydrateFromBlockNameImpl (core.mjs:22403:91)
    at core.mjs:22445:16
    at Generator.next (<anonymous>)
    at chunk-4MWRP73S.js?v=7a14075d:76:61

Similarly when using the second code block, incremental hydration works as expected on hard page load i.e. when isLoggedIn() is true, this div gets removed. But that doesn't seem to be the case with the first code block.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

core.mjs:7283 ERROR TypeError: Cannot read properties of undefined (reading 'p')
at findFirstKnownParentDeferBlock (core.mjs:22378:54)
at core.mjs:22414:7
at Generator.next ()
at chunk-4MWRP73S.js?v=7a14075d:76:61
at new ZoneAwarePromise (zone.js:2702:25)
at __async (chunk-4MWRP73S.js?v=7a14075d:60:10)
at hydrateFromBlockNameImpl (core.mjs:22403:91)
at core.mjs:22445:16
at Generator.next ()
at chunk-4MWRP73S.js?v=7a14075d:76:61

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

@angular-devkit/architect 0.1900.0-next.13
@angular-devkit/build-angular 19.0.0-next.13
@angular-devkit/core 18.2.4
@angular-devkit/schematics 18.2.4
@angular/cdk 19.0.0-next.10
@angular/cli 19.0.0-next.13
@angular/fire 18.0.1
@angular/google-maps 19.0.0-next.10
@angular/material 19.0.0-next.10
@angular/pwa 19.0.0-next.13
@angular/ssr 19.0.0-next.13
@schematics/angular 18.2.4
rxjs 7.8.1
typescript 5.6.2
zone.js 0.15.0

Anything else?

No response

Activity

  1. naveedahmed1 commented on Oct 25, 2024

    @naveedahmed1
    ContributorAuthor
  2. naveedahmed1 commented on Oct 25, 2024

    @naveedahmed1
    ContributorAuthor

    Maybe its not just about client side navigation, I am seeing similar error for cases like when i have:

    @defer(hydrate when applyFormIsOpen()) {
            @if(!applyFormIsOpen()){
            <div class="mat-card mb15">
            </div>
            }
    }
    
    

    And applyFormIsOpen signal is updated through some action e.g.:

    <button (click)="openApplyForm()>Apply Now</button>
    
    openApplyForm(){
            this.applyFormIsOpen.set(true);
    }
    
  3. thePunderWoman commented on Oct 25, 2024

    @thePunderWoman
    Contributor

    It is definitely client side navigation related where hydrate triggers are attempting to fire at the wrong time. The fix should land on Monday.

  4. added
    area: core
    on Oct 25, 2024
  5. modified the milestone: needsTriage on Oct 25, 2024
  6. naveedahmed1 commented on Oct 25, 2024

    @naveedahmed1
    ContributorAuthor

    This was pretty quick! Thank you so much, enjoy your weekend.

  7. added
    P2
    on Oct 25, 2024
  8. 12 remaining items

  9. AndrewKushnir commented on Oct 26, 2024

    @AndrewKushnir
    Contributor

    Thanks Andrew, I'm not sure how to update this code, are you referring to updating the code in the sources tab in the dev console? If I do that a page refresh would reset the changes, and error occurs on page load. Is there any specific file you want me to update?

    You may try patching corresponding file in the node_modules directly and rebuild the project. Note: you'd also need to clear the build cache by running ng cache clean before rebuilding the project.

  10. naveedahmed1 commented on Oct 26, 2024

    @naveedahmed1
    ContributorAuthor

    It seems that ng cache clean actully fixed the issue, I think I mised ng cache clean step when updating packages to https://github.com/angular/angular/actions/runs/11523797513/artifacts/2105790303

  11. naveedahmed1 commented on Oct 26, 2024

    @naveedahmed1
    ContributorAuthor

    Although I am no longer seeing that error message in console. But it seems that Incremental Hydration isn't working with ng build output when deployed.

    For example I have a form with @defer(hydrate on interaction) and when running ng serve, interaction with form input fields hydrate it, i.e. ngb="d8" attribute gets removed.

    But when using ng build and deploying, the hydration doesnt work, it doesnt throw errors, but doesnt remove ngb="d8" attribute either. And form submit starts hard navigation.

    I think its the same behavior that I reported during the initial testing of partial hydration.

  12. naveedahmed1 commented on Oct 27, 2024

    @naveedahmed1
    ContributorAuthor

    To me more specific:

    Below triggers are not working when deployed:

    • timer
    • hover
    • interaction
    • when

    Whereas below seems to be working fine:

    • immediate
    • idle
    • on viewport
    • never
  13. naveedahmed1 commented on Oct 28, 2024

    @naveedahmed1
    ContributorAuthor

    Let me share another case, since it seems related:

    I have a jobs list component:

    @defer(on idle; prefetch on immediate; hydrate on idle) {
    <jobs-list [list]="list()" [city]="city()" [scrollToId]="scrollToId()" [logo]="true" [adRegion]="'page-jobs-list'" [showSecondAdUnit]="true">Loading...</jobs-list>
    }
    

    In the jobs list component I have an ad unit with hydrate never:

    @defer(on idle; prefetch on immediate; hydrate never){
     <div class="mat-card mb10 p0 list-inline-ad-unit">
      <!--in-list ad unit 1-->
       <div adUnitWithHydration [adSlot]="7925136684" [adRegion]="adRegion()" [fullWidthResponsive]="true"></div>
    </div>
    }
    

    This throw error on directly visiting the jobs list page or on hard reload (i.e. with SSR response):

    adsbygoogle.js?client=ca-pub-6815942738114816:62 Error: no_div
        at adsbygoogle.js?client=ca-pub-6815942738114816:157:423
        at tf.ea (adsbygoogle.js?client=ca-pub-6815942738114816:62:196)
        at ho (adsbygoogle.js?client=ca-pub-6815942738114816:155:614)
        at adsbygoogle.js?client=ca-pub-6815942738114816:155:661
        at adsbygoogle.js?client=ca-pub-6815942738114816:62:392
        at tf.ea (adsbygoogle.js?client=ca-pub-6815942738114816:62:196)
        at adsbygoogle.js?client=ca-pub-6815942738114816:62:381
        at P.<computed> (polyfills-FFHMD2TL.js:1:21493)
        at f.invokeTask (polyfills-FFHMD2TL.js:1:7068)
        at t.runTask (polyfills-FFHMD2TL.js:1:2375)
    

    My understanding is, on hydration of jobs-list component, the ad unit code should remain untouched, since its enclosed in hydrate never block. But it seems that its being updated as well, thats why, adsense is throwing error.

  14. added a commit that references this issue on Oct 29, 2024
    fd77164
  15. added a commit that references this issue on Oct 29, 2024
    acd4f80
  16. naveedahmed1 commented on Oct 29, 2024

    @naveedahmed1
    ContributorAuthor

    @alan-agius4 can you please create a new project using Cloudflare Pages Angular template, add incremental hydration with below triggers, deploy it and see if it works fine on your side?

    timer
    hover
    interaction
    when

    ref: #58359 (comment)

  17. thePunderWoman commented on Oct 29, 2024

    @thePunderWoman
    Contributor

    @naveedahmed1 With your supplemental issues, can you please create a new issue per item focused on each individual issue as a bug for us? And then with each, we really need a minimal reproduction rather than using your application. Your app has such a custom setup that it makes it more difficult to diagnose what's going on. Each individual bug will help us track these and address them faster. Thanks for the help!

  18. angular-automatic-lock-bot commented on Nov 29, 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.

  19. locked and limited conversation to collaborators on Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2area: corecore: hydrationstate: has PR

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions