@@ -100,7 +100,7 @@ export const ColumnAutoWidthMixin = (superClass) =>
100
100
101
101
const columnWidth = Math . max (
102
102
this . __getIntrinsicWidth ( col ) ,
103
- this . __getDistributedWidth ( ( col . assignedSlot || col ) . parentElement , col ) ,
103
+ this . __getDistributedWidth ( this . __getParentColumnGroup ( col ) , col ) ,
104
104
) ;
105
105
106
106
// We're processing a regular grid-column and not a grid-column-group
@@ -153,13 +153,38 @@ export const ColumnAutoWidthMixin = (superClass) =>
153
153
const lvi = this . _lastVisibleIndex ;
154
154
this . __viewportRowsCache = this . _getRenderedRows ( ) . filter ( ( row ) => row . index >= fvi && row . index <= lvi ) ;
155
155
156
- // Pre-cache the intrinsic width of each column
156
+ // Get columns with autoWidth
157
157
const cols = this . __getAutoWidthColumns ( ) ;
158
- this . __calculateAndCacheIntrinsicWidths ( cols ) ;
158
+
159
+ // Get all ancestor groups of the columns
160
+ const ancestorColumnGroups = new Set ( ) ;
161
+ for ( const col of cols ) {
162
+ let parent = this . __getParentColumnGroup ( col ) ;
163
+ while ( parent && ! ancestorColumnGroups . has ( parent ) ) {
164
+ ancestorColumnGroups . add ( parent ) ;
165
+ parent = this . __getParentColumnGroup ( parent ) ;
166
+ }
167
+ }
168
+
169
+ // Pre-cache the intrinsic width of each column and ancestor group
170
+ this . __calculateAndCacheIntrinsicWidths ( [ ...cols , ...ancestorColumnGroups ] ) ;
159
171
160
172
cols . forEach ( ( col ) => {
161
173
col . width = `${ this . __getDistributedWidth ( col ) } px` ;
162
174
} ) ;
175
+
176
+ // Clear the column-width cache to avoid a memory leak
177
+ this . __intrinsicWidthCache . clear ( ) ;
178
+ }
179
+
180
+ /**
181
+ * Returns the parent column group of the given column.
182
+ *
183
+ * @private
184
+ */
185
+ __getParentColumnGroup ( col ) {
186
+ const parent = ( col . assignedSlot || col ) . parentElement ;
187
+ return parent && parent !== this ? parent : null ;
163
188
}
164
189
165
190
/**
0 commit comments