@hyphen/hyphen-components 6.2.2 → 6.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyphen/hyphen-components",
3
- "version": "6.2.2",
3
+ "version": "6.2.3",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "@hyphen"
@@ -68,3 +68,21 @@ describe('Responsive hooks', () => {
68
68
  ).toEqual(1);
69
69
  });
70
70
  });
71
+
72
+ describe('Cleanup', () => {
73
+ it('clears pending resize timeout on unmount', () => {
74
+ jest.useFakeTimers();
75
+ const clearSpy = jest.spyOn(window, 'clearTimeout');
76
+ const { unmount } = render(
77
+ <ResponsiveProvider throttle={100}>
78
+ <div />
79
+ </ResponsiveProvider>
80
+ );
81
+ window.dispatchEvent(new Event('resize'));
82
+ expect(clearSpy).toHaveBeenCalledTimes(1);
83
+ unmount();
84
+ expect(clearSpy).toHaveBeenCalledTimes(2);
85
+ clearSpy.mockRestore();
86
+ jest.useRealTimers();
87
+ });
88
+ });
@@ -53,7 +53,10 @@ export const ResponsiveProvider: React.FC<ResponsiveProviderProps> = ({
53
53
 
54
54
  window.addEventListener('resize', throttledResize);
55
55
 
56
- return () => window.removeEventListener('resize', throttledResize);
56
+ return () => {
57
+ window.removeEventListener('resize', throttledResize);
58
+ clearTimeout(timeoutId);
59
+ };
57
60
  }
58
61
  }, [throttle]);
59
62