Skip to content

Commit 6b3e6e0

Browse files
committed
fix(cdk-experimental/scrolling): Fix ExpressionChangedAfterItWasCheckedError
This fixes an expressionchanged... error in the scrolling where template updates were not accompanied by a change notification (`markforCheck`/signal update, etc).
1 parent 82c4484 commit 6b3e6e0

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

goldens/cdk/scrolling/index.api.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
205205
setRenderedContentOffset(offset: number, to?: 'to-start' | 'to-end'): void;
206206
setRenderedRange(range: ListRange): void;
207207
setTotalContentSize(size: number): void;
208-
_totalContentHeight: string;
209-
_totalContentWidth: string;
208+
_totalContentHeight: i0.WritableSignal<string>;
209+
_totalContentWidth: i0.WritableSignal<string>;
210210
// (undocumented)
211211
static ɵcmp: i0.ɵɵComponentDeclaration<CdkVirtualScrollViewport, "cdk-virtual-scroll-viewport", never, { "orientation": { "alias": "orientation"; "required": false; }; "appendOnly": { "alias": "appendOnly"; "required": false; }; }, { "scrolledIndexChange": "scrolledIndexChange"; }, never, ["*"], true, never>;
212212
// (undocumented)

src/cdk-experimental/scrolling/virtual-scroll-viewport.spec.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import {CdkVirtualScrollViewport, ScrollingModule} from '@angular/cdk/scrolling';
2-
import {
3-
Component,
4-
Input,
5-
provideCheckNoChangesConfig,
6-
ViewChild,
7-
ViewEncapsulation,
8-
} from '@angular/core';
2+
import {Component, Input, ViewChild, ViewEncapsulation} from '@angular/core';
93
import {ComponentFixture, TestBed, fakeAsync, flush, waitForAsync} from '@angular/core/testing';
104
import {ScrollingModule as ExperimentalScrollingModule} from './scrolling-module';
115

@@ -17,7 +11,6 @@ describe('CdkVirtualScrollViewport', () => {
1711

1812
beforeEach(waitForAsync(() => {
1913
TestBed.configureTestingModule({
20-
providers: [provideCheckNoChangesConfig({exhaustive: false})],
2114
imports: [ScrollingModule, ExperimentalScrollingModule, AutoSizeVirtualScroll],
2215
});
2316
}));

src/cdk/scrolling/virtual-scroll-viewport.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
so that the scrollbar captures the size of the entire data set.
1111
-->
1212
<div class="cdk-virtual-scroll-spacer"
13-
[style.width]="_totalContentWidth" [style.height]="_totalContentHeight"></div>
13+
[style.width]="_totalContentWidth()" [style.height]="_totalContentHeight()"></div>

src/cdk/scrolling/virtual-scroll-viewport.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
OnInit,
2424
Optional,
2525
Output,
26+
signal,
2627
ViewChild,
2728
ViewEncapsulation,
2829
} from '@angular/core';
@@ -137,10 +138,10 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
137138
private _totalContentSize = 0;
138139

139140
/** A string representing the `style.width` property value to be used for the spacer element. */
140-
_totalContentWidth = '';
141+
_totalContentWidth = signal('');
141142

142143
/** A string representing the `style.height` property value to be used for the spacer element. */
143-
_totalContentHeight = '';
144+
_totalContentHeight = signal('');
144145

145146
/**
146147
* The CSS transform applied to the rendered subset of items so that they appear within the bounds
@@ -533,9 +534,11 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On
533534

534535
/** Calculates the `style.width` and `style.height` for the spacer element. */
535536
private _calculateSpacerSize() {
536-
this._totalContentHeight =
537-
this.orientation === 'horizontal' ? '' : `${this._totalContentSize}px`;
538-
this._totalContentWidth =
539-
this.orientation === 'horizontal' ? `${this._totalContentSize}px` : '';
537+
this._totalContentHeight.set(
538+
this.orientation === 'horizontal' ? '' : `${this._totalContentSize}px`,
539+
);
540+
this._totalContentWidth.set(
541+
this.orientation === 'horizontal' ? `${this._totalContentSize}px` : '',
542+
);
540543
}
541544
}

0 commit comments

Comments
 (0)