Skip to content

Commit 1b59e32

Browse files
committed
Copy tweaks
1 parent 8bb3f35 commit 1b59e32

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

changelogs/upcoming/7468.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
**Bug fixes**
22

3-
- Fixed an issue in `EuiResizableContainer` where `onResizeEnd` becomes a stale closure when renders occur between resize start and end. This can result in an outdated version of a consumer's `onResizeEnd` callback being called on resize end.
3+
- Fixed an issue in `EuiResizableContainer` where `onResizeEnd` could become a stale closure when renders occured between resize start and end, resulting in an outdated version of a consumer's `onResizeEnd` callback being called

src/components/resizable_container/resizable_container.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe('EuiResizableContainer', () => {
350350
expect(onResizeEnd).toHaveBeenCalledTimes(1);
351351
});
352352

353-
test('unmemoized consumer onResizeStart/End callbacks are handled', () => {
353+
test('unmemoized consumer onResizeStart/End callbacks do not cause stale closures', () => {
354354
const ConsumerUsage = () => {
355355
const [rerender, setRerender] = useState(0);
356356
// Unmemoized consumer callbacks
@@ -387,7 +387,8 @@ describe('EuiResizableContainer', () => {
387387

388388
fireEvent.mouseUp(getByTestSubject('euiResizableButton'));
389389
expect(getByTestSubject('rerenders')).toHaveTextContent('2');
390-
// Without `useLatest`, the rerender count doesn't correctly update due to `onResizeEnd` not being memoized and causing the wrong `resizeEnd` to be called on event listener end
390+
// Without `useLatest`, the rerender count doesn't correctly update due to `onResizeEnd`
391+
// not being memoized and causing a stale `resizeEnd` closure to be called on event end
391392
});
392393
});
393394
});

src/components/resizable_container/resizable_container.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const EuiResizableContainer: FunctionComponent<
101101
...rest
102102
}) => {
103103
// Note: It's important to memoize consumer callbacks to prevent our own functions
104-
// from reinstantiating unnecessarily and breaking our window event listeners
104+
// from reinstantiating unnecessarily & causing window event listeners to call stale closures
105105
const onResizeEndRef = useLatest(onResizeEnd);
106106
const onResizeStartRef = useLatest(onResizeStart);
107107
const containerRef = useRef<HTMLDivElement>(null);

0 commit comments

Comments
 (0)