Skip to content

fix(cdk/table): support hydration #28356

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 8, 2024

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jan 3, 2024

Reworks the table so that it can support hydration. There were a few issues that broke hydration:

  1. There wasn't a catch-all ng-content slot which meant that the comment nodes representing the table content were dropped, causing an error.
  2. The table needs to conditionally wrap some content with native table sections (thead, tbody etc.) which was done with direct DOM manipulation. This breaks hydration because Angular won't know about those elements.

The first issue is easily resolved by adding an ng-content element. It shouldn't affect existing tables, since all the projected content is composed of comment nodes.

The second issue is a bit trickier, because we were using content queries to resolve the individual table outlets. Wrapping them in a conditional breaks the query so we have to use something else to resolve them. I've worked around it by using DI which doesn't have the exact same timing, but it appears to be close enough.

Fixes #28355.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release labels Jan 3, 2024
}

/** Renders the table if its state has changed. */
private _render(): void {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a big diff, but I basically just moved the code from ngAfterContentChecked into a separate method.

@crisbeto crisbeto force-pushed the table-hydration-exploration branch from 9b72bb3 to ed8e3c0 Compare January 3, 2024 09:57
Reworks the table so that it can support hydration. There were a few issues that broke hydration:
1. There wasn't a catch-all `ng-content` slot which meant that the comment nodes representing the table content were dropped, causing an error.
2. The table needs to conditionally wrap some content with native table sections (`thead`,  `tbody` etc.) which was done with direct DOM manipulation. This breaks hydration because Angular won't know about those elements.

The first issue is easily resolved by adding an `ng-content` element. It shouldn't affect existing tables, since all the projected content is composed of comment nodes.

The second issue is a bit trickier, because we were using content queries to resolve the individual table outlets. Wrapping them in a conditional breaks the query so we have to use something else to resolve them. I've worked around it by using DI which doesn't have the exact same timing, but it appears to be close enough.

Fixes angular#28355.
@crisbeto crisbeto force-pushed the table-hydration-exploration branch from ed8e3c0 to 3035d33 Compare January 3, 2024 11:11
@crisbeto crisbeto self-assigned this Jan 3, 2024
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker 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 3, 2024
@crisbeto crisbeto merged commit 30f0705 into angular:main Jan 8, 2024
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 9, 2024
Fixes that after angular#28356 the table rows were measured too early which caused multiple sticky rows not to work as expected.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Jan 9, 2024
Fixes that after angular#28356 the table rows were measured too early which caused multiple sticky rows not to work as expected.
crisbeto added a commit that referenced this pull request Jan 10, 2024
Fixes that after #28356 the table rows were measured too early which caused multiple sticky rows not to work as expected.
@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 8, 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 P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(mat-table): Mat Table has skip hydration attribute
2 participants