Skip to content

Commit 408134f

Browse files
crisbetojelbourn
authored andcommitted
fix(autosize): error thrown by IE in some cases when component is destroyed (#11109)
Fixes IE throwing an "Unspecified error" if an autosize textarea is destroyed between the time it requests an animation frame and when the animation frame is executed. The error manifested itself in our unit tests where the last animation frame usually fires after the test case has run.
1 parent 0c7998c commit 408134f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/cdk/text-field/autosize.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
204204
if (typeof requestAnimationFrame !== 'undefined') {
205205
this._ngZone.runOutsideAngular(() => requestAnimationFrame(() => {
206206
const {selectionStart, selectionEnd} = textarea;
207-
textarea.setSelectionRange(selectionStart, selectionEnd);
207+
208+
// IE will throw an "Unspecified error" if we try to set the selection range after the
209+
// element has been removed from the DOM. Assert that the directive hasn't been destroyed
210+
// between the time we requested the animation frame and when it was executed.
211+
if (!this._destroyed.isStopped) {
212+
textarea.setSelectionRange(selectionStart, selectionEnd);
213+
}
208214
}));
209215
}
210216

0 commit comments

Comments
 (0)