Skip to content

Commit 810f79e

Browse files
jcfrancobenelan
authored andcommitted
fix(text-area): fix error caused by internal measuring on disconnect (#11751)
1 parent c5d12d0 commit 810f79e

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

packages/calcite-components/src/components/text-area/resources.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ export const SLOTS = {
2727
};
2828

2929
export const RESIZE_TIMEOUT = 100;
30+
31+
export const NO_DIMENSIONS = Object.freeze({ height: 0, width: 0 });

packages/calcite-components/src/components/text-area/text-area.e2e.ts

+28
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
themed,
1515
} from "../../tests/commonTests";
1616
import { html } from "../../../support/formatting";
17+
import { newProgrammaticE2EPage } from "../../tests/utils";
1718
import { CSS } from "./resources";
1819

1920
describe("calcite-text-area", () => {
@@ -214,6 +215,33 @@ describe("calcite-text-area", () => {
214215
});
215216
});
216217

218+
it("does not throw when removed early in the cycle (#11514)", async () => {
219+
async function runTest(): Promise<void> {
220+
const page = await newProgrammaticE2EPage();
221+
await page.evaluate(async () => {
222+
await new Promise<void>((resolve) => {
223+
const textArea = document.createElement("calcite-text-area");
224+
let firstResize = false;
225+
const resizeObserver = new ResizeObserver(async () => {
226+
if (!firstResize) {
227+
firstResize = true;
228+
return;
229+
}
230+
231+
resizeObserver.disconnect();
232+
textArea.remove();
233+
resolve();
234+
});
235+
document.body.append(textArea);
236+
resizeObserver.observe(textArea);
237+
});
238+
});
239+
await page.waitForChanges();
240+
}
241+
242+
await expect(runTest()).resolves.toBeUndefined();
243+
});
244+
217245
describe("translation support", () => {
218246
t9n("calcite-text-area");
219247
});

packages/calcite-components/src/components/text-area/text-area.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { useT9n } from "../../controllers/useT9n";
3838
import type { Label } from "../label/label";
3939
import { CharacterLengthObj } from "./interfaces";
4040
import T9nStrings from "./assets/t9n/messages.en.json";
41-
import { CSS, IDS, SLOTS, RESIZE_TIMEOUT } from "./resources";
41+
import { CSS, IDS, NO_DIMENSIONS, RESIZE_TIMEOUT, SLOTS } from "./resources";
4242
import { styles } from "./text-area.scss";
4343

4444
declare global {
@@ -402,12 +402,13 @@ export class TextArea
402402
footerHeight: number;
403403
footerWidth: number;
404404
} {
405-
const { height: textAreaHeight, width: textAreaWidth } =
406-
this.textAreaEl.getBoundingClientRect();
405+
const { height: textAreaHeight, width: textAreaWidth } = this.textAreaEl
406+
? this.textAreaEl.getBoundingClientRect()
407+
: NO_DIMENSIONS;
407408
const { height: elHeight, width: elWidth } = this.el.getBoundingClientRect();
408409
const { height: footerHeight, width: footerWidth } = this.footerEl.value
409410
? this.footerEl.value.getBoundingClientRect()
410-
: { height: 0, width: 0 };
411+
: NO_DIMENSIONS;
411412

412413
return {
413414
textAreaHeight,

0 commit comments

Comments
 (0)