Skip to content

Commit 6a7da01

Browse files
authored
Merge pull request #67 from easyops-cn/steve/fix-resize-entry
fix(): fix resize entry in old Firefox
2 parents 458bad1 + 72f06d6 commit 6a7da01

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

bricks/form/src/textarea/index.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ describe("eo-textarea", () => {
185185
);
186186

187187
expect(requestAnimationFrame).toBeCalledTimes(1);
188+
const target = element.shadowRoot?.querySelector("eo-form-item");
188189

189190
act(() => {
190191
observerCallback?.(
191192
[
192193
{
194+
target,
193195
contentBoxSize: [{ inlineSize: 300, blockSize: 100 }],
194196
} as any,
195197
],
@@ -202,6 +204,7 @@ describe("eo-textarea", () => {
202204
observerCallback?.(
203205
[
204206
{
207+
target,
205208
contentBoxSize: [{ inlineSize: 300, blockSize: 120 }],
206209
} as any,
207210
],
@@ -210,10 +213,25 @@ describe("eo-textarea", () => {
210213
});
211214
expect(requestAnimationFrame).toBeCalledTimes(1);
212215

216+
// Target not matched.
213217
act(() => {
214218
observerCallback?.(
215219
[
216220
{
221+
target: null,
222+
contentBoxSize: [{ inlineSize: 320, blockSize: 120 }],
223+
} as any,
224+
],
225+
null!
226+
);
227+
});
228+
expect(requestAnimationFrame).toBeCalledTimes(1);
229+
230+
act(() => {
231+
observerCallback?.(
232+
[
233+
{
234+
target,
217235
contentBoxSize: [{ inlineSize: 320, blockSize: 120 }],
218236
} as any,
219237
],

bricks/form/src/textarea/index.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,25 @@ export const TextareaComponent = forwardRef<
282282
}
283283
let previousInlineSize: number | undefined;
284284
const observer = new ResizeObserver((entries) => {
285-
const currentInlineSize = entries[0]?.contentBoxSize[0]?.inlineSize;
286-
if (
287-
currentInlineSize !== undefined &&
288-
currentInlineSize !== previousInlineSize
289-
) {
290-
const isInitial = !previousInlineSize;
291-
previousInlineSize = currentInlineSize;
292-
if (!isInitial) {
293-
requestAnimationFrame(setAutoSize);
285+
for (const entry of entries) {
286+
if (entry.target === container) {
287+
// istanbul ignore next: compatibility
288+
const currentInlineSize = entry.contentBoxSize
289+
? entry.contentBoxSize[0]
290+
? entry.contentBoxSize[0].inlineSize
291+
: (entry.contentBoxSize as unknown as ResizeObserverSize)
292+
.inlineSize
293+
: entry.contentRect.width;
294+
if (
295+
currentInlineSize !== undefined &&
296+
currentInlineSize !== previousInlineSize
297+
) {
298+
const isInitial = !previousInlineSize;
299+
previousInlineSize = currentInlineSize;
300+
if (!isInitial) {
301+
requestAnimationFrame(setAutoSize);
302+
}
303+
}
294304
}
295305
}
296306
});

bricks/mini-chart/src/mini-line-chart/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,22 @@ export function MiniLineChartComponent({
178178
for (const entry of entries) {
179179
if (entry.target === root) {
180180
if (autoWidth) {
181-
// istanbul ignore next
181+
// istanbul ignore next: compatibility
182182
const newWidth = entry.contentBoxSize
183-
? entry.contentBoxSize[0].inlineSize
183+
? entry.contentBoxSize[0]
184+
? entry.contentBoxSize[0].inlineSize
185+
: (entry.contentBoxSize as unknown as ResizeObserverSize)
186+
.inlineSize
184187
: entry.contentRect.width;
185188
setWidth(newWidth);
186189
}
187190
if (autoHeight) {
188-
// istanbul ignore next
191+
// istanbul ignore next: compatibility
189192
const newHeight = entry.contentBoxSize
190-
? entry.contentBoxSize[0].blockSize
193+
? entry.contentBoxSize[0]
194+
? entry.contentBoxSize[0].blockSize
195+
: (entry.contentBoxSize as unknown as ResizeObserverSize)
196+
.blockSize
191197
: entry.contentRect.height;
192198
setHeight(newHeight);
193199
}

bricks/vs/src/code-editor/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,11 +538,19 @@ export function CodeEditorComponent({
538538
const observer = new ResizeObserver((entries) => {
539539
for (const entry of entries) {
540540
if (entry.target === containerRef.current) {
541+
// istanbul ignore next: compatibility
541542
const newWidth = entry.contentBoxSize
542-
? entry.contentBoxSize[0].inlineSize
543+
? entry.contentBoxSize[0]
544+
? entry.contentBoxSize[0].inlineSize
545+
: (entry.contentBoxSize as unknown as ResizeObserverSize)
546+
.inlineSize
543547
: entry.contentRect.width;
548+
// istanbul ignore next: compatibility
544549
const newHeight = entry.contentBoxSize
545-
? entry.contentBoxSize[0].blockSize
550+
? entry.contentBoxSize[0]
551+
? entry.contentBoxSize[0].blockSize
552+
: (entry.contentBoxSize as unknown as ResizeObserverSize)
553+
.blockSize
546554
: entry.contentRect.height;
547555
if (newWidth !== size.current.width || expanded) {
548556
size.current.width = newWidth;

0 commit comments

Comments
 (0)