Skip to content

Commit 3035d33

Browse files
committed
fix(cdk/table): support hydration
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.
1 parent 38c8778 commit 3035d33

File tree

7 files changed

+302
-156
lines changed

7 files changed

+302
-156
lines changed

src/cdk/table/sticky-styler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ export class StickyStyler {
258258
return;
259259
}
260260

261-
const tfoot = tableElement.querySelector('tfoot')!;
262-
263261
// Coalesce with other sticky updates (and potentially other changes like column resize).
264262
this._coalescedStyleScheduler.schedule(() => {
263+
const tfoot = tableElement.querySelector('tfoot')!;
264+
265265
if (stickyStates.some(state => !state)) {
266266
this._removeStickyStyle(tfoot, ['bottom']);
267267
} else {

0 commit comments

Comments
 (0)