Skip to content

hydration problems with ng-content #50175

Closed

Description

@robertIsaac

🐞 Bug report

What modules are related to this issue?

  • builders
  • common
  • express-engine

Is this a regression?

no

Description

when enabling hydration and passing content with ng-content, the ng-content is filled with nothing

3 changes that fixes the issue

  1. instead of using Material to use <div><ng-content></ng-content></div> (so it only happens with Angular Material, no idea why sorry)
  2. if I moved the actual content inside the layout component instead of passing it from app.component.html
  3. remove provideClientHydration()

🔬 Minimal Reproduction

https://github.com/robertIsaac/hydration-problem

🔥 Exception or Error

NA

🌍 Your Environment


Angular CLI: 16.0.0
Node: 16.18.1
Package Manager: npm 8.19.2
OS: win32 x64

Angular: 16.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... platform-server, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1600.0
@angular-devkit/build-angular   16.0.0
@angular-devkit/core            16.0.0
@angular-devkit/schematics      16.0.0
@nguniversal/builders           16.0.0
@nguniversal/express-engine     16.0.0
@schematics/angular             16.0.0
rxjs                            7.8.1
typescript                      5.0.4

Activity

  1. added
    area: core
    on May 6, 2023
  2. added this to the needsTriage milestone on May 6, 2023
  3. added
    P3
    on May 6, 2023
  4. self-assigned this
    on May 6, 2023
  5. modified the milestones: needsTriage, Backlog on May 6, 2023
  6. AndrewKushnir commented on May 6, 2023

    @AndrewKushnir
    Contributor

    @robertIsaac thanks for reporting the problem and sharing a repro, the repro is very helpful 👍

    I noticed is that the problem happens when there is a view container (*ngFor) in use:

     <app-layout>
      <p *ngFor="let content of fillerContent">{{content}}</p>
     </app-layout>
    

    when there is no view container as a root node, content projection works fine.

    As a temporary solution, you could try wrapping projected content into an element like this:

     <app-layout>
       <div>
         <p *ngFor="let content of fillerContent">{{content}}</p>
       </div>
     </app-layout>
    

    We'll perform further investigation and will keep this thread updated.

    Thank you.

  7. robertIsaac commented on May 6, 2023

    @robertIsaac
    ContributorAuthor

    @robertIsaac thanks for reporting the problem and sharing a repro, the repro is very helpful 👍

    I noticed is that the problem happens when there is a view container (*ngFor) in use:

     <app-layout>
      <p *ngFor="let content of fillerContent">{{content}}</p>
     </app-layout>
    

    when there is no view container as a root node, content projection works fine.

    As a temporary solution, you could try wrapping projected content into an element like this:

     <app-layout>
       <div>
         <p *ngFor="let content of fillerContent">{{content}}</p>
       </div>
     </app-layout>
    

    We'll perform further investigation and will keep this thread updated.

    Thank you.

    Well in the real case there is no ngfor and it doesn't work, but it's complicated one

    FYI using router-outlet also make it not working

  8. AndrewKushnir commented on May 7, 2023

    @AndrewKushnir
    Contributor

    FYI using router-outlet also make it not working

    Thanks for additional information. The <router-outlet> under the hood also uses view container APIs to create a component for a route, so this may have the same root cause. I was able to reproduce the problem locally and the issue happens when a view container is projected from a hydrated component to a component that skips hydration (and re-creates all nodes). I'll work on a fix and share an update when I have it.

    Meanwhile, could you please try wrapping the <router-outlet> into an extra element to see if that resolves the issue? For example:

    <app-layout>
      <div>
        <router-outlet />
      </div>
    </app-layout>
    

    Thank you.

  9. added
    P2
    and removed
    P3
    on May 8, 2023
  10. AndrewKushnir commented on May 8, 2023

    @AndrewKushnir
    Contributor

    @robertIsaac I've created a draft version of a fix for this issue, could you please try to test the behavior of your application with this fix applied?

    You can update the package.json file locally and replace the @angular/core dependency with the following package:

      ...
      "@angular/core": "https://output.circle-artifacts.com/output/job/9a9e6935-0c92-4744-aedb-a26d79e479d4/artifacts/0/angular/core-pr50199-adc2a499e1.tgz",
      ...
    

    After that you can run npm install --force and test the behavior of the app once again.

    Please let us know if that resolved the issue.

    Thank you.

  11. 3 remaining items

  12. AndrewKushnir commented on May 9, 2023

    @AndrewKushnir
    Contributor

    @robertIsaac thanks for the update. The fix was applied to the Embedded Views code path only, but not the Component path. I've added the necessary changes and you can test the behavior using the following package:

      ...
      "@angular/core": "https://output.circle-artifacts.com/output/job/20b4bcba-871c-4700-a621-d4f9dcb60f78/artifacts/0/angular/core-pr50199-ec9f3d6e6c.tgz",
      ...
    

    I've tested this package with the repro and hydration works correctly there now. Could you please try to test the fix in your real application as well and let us know if it resolved the issue?

    Thank you.

  13. added a commit that references this issue on May 9, 2023
    9bbecbd
  14. added a commit that references this issue on May 9, 2023
    f751ce6
  15. AndrewKushnir commented on May 10, 2023

    @AndrewKushnir
    Contributor

    Just wanted to share a quick update: Angular v16.0.1 was released today. Angular v16.0.1 includes the fix for this issue, please try updating to v16.0.1 and let us know if he problem still exists. Thank you.

  16. robertIsaac commented on May 10, 2023

    @robertIsaac
    ContributorAuthor

    Just wanted to share a quick update: Angular v16.0.1 was released today. Angular v16.0.1 includes the fix for this issue, please try updating to v16.0.1 and let us know if he problem still exists. Thank you.

    thank you for your update and quick fix
    I confirm the reprod works fine, but for my application I can't verify it for now, if when I test it found the problem still existing I add a new comment here

  17. added 2 commits that reference this issue on May 19, 2023
    d963ecd
    2f1796f
  18. angular-automatic-lock-bot commented on Jun 10, 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.

  19. locked and limited conversation to collaborators on Jun 10, 2023
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

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions