Skip to content

fix(material/tabs): enable hydration #28366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jan 4, 2024

Adds a workaround that allows us to enable hydration in the tab group component.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jan 4, 2024
3. We get a hydration error if `ng-content` is wrapped in another element.
-->
@if (_isServer) {
<ng-content/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed? I don't follow and would like to understand more. Why isn't this needed with CSR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nodes that were projected have to match the nodes that are rendered out or the runtime will throw a hydration error. For the tabs specifically without the ng-content we'll end up dropping the <mat-tab> node and the anchor comment inside of it which are necessary for hydration. This workaround keeps the nodes around during SSR and then drops them once hydration is done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, I see what you're saying. I would have expected the mat-tab to be resolved as well and have it's content SSR-ed as well. That seems like a surprising requirement for projection?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit weird, but it's kinda expected. If the mat-tab doesn't get projected, when the HTML makes it to the browser, it won't know that it existed when it was created on the server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels surprising to me that component authors would need to take care of that. It almost sounds like a bug to me that it works in CSR like that (talking about ContentChildren matching without a ng-content`).

The change makes sense, but would love the comment to capture this as well, but no need to re-push. Also cc. @AndrewKushnir as some user-facing feedback on hydration potentially

@crisbeto crisbeto force-pushed the tabs-hydration-simple branch from 87dde50 to 1fcb903 Compare January 4, 2024 12:33
@crisbeto crisbeto force-pushed the tabs-hydration-simple branch from 1fcb903 to a130797 Compare January 4, 2024 20:29
Adds a workaround that allows us to enable hydration in the tab group component.
@crisbeto crisbeto force-pushed the tabs-hydration-simple branch from a130797 to cdf8980 Compare January 4, 2024 20:31
@crisbeto crisbeto self-assigned this Jan 4, 2024
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jan 4, 2024
@crisbeto crisbeto removed the request for review from josephperrott January 4, 2024 20:35
@crisbeto crisbeto added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Jan 4, 2024
@crisbeto crisbeto merged commit a7f87a8 into angular:main Jan 4, 2024
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants