@wistia/ui 3.2.0 → 3.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4574](https://github.com/wistia/vhs/pull/4574) [`c910d5a`](https://github.com/wistia/vhs/commit/c910d5a14ccaf54f7717414a42fc5a08755e766a) Thanks [@okize](https://github.com/okize)! - `useWindowSize` and `useMq`: a resize just before the component unmounts no longer updates the size after the component is gone. Before, the queued update still ran and read `window`, which threw `ReferenceError: window is not defined` when a test environment was already torn down.
8
+
9
+ `useWindowSize`: changing `interval` now reads the window size at once, so a queued update is not lost. A resize that leaves the size unchanged no longer re-renders the component.
10
+
3
11
  ## 3.2.0
4
12
 
5
13
  ### Minor Changes
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  /*
3
- * @license @wistia/ui v3.2.0
3
+ * @license @wistia/ui v3.2.1
4
4
  *
5
5
  * Copyright (c) 2024-2026, Wistia, Inc. and its affiliates.
6
6
  *
@@ -1798,12 +1798,20 @@ const useWindowSize = (interval = 0) => {
1798
1798
  height: isClient() ? window.innerHeight : 0
1799
1799
  });
1800
1800
  useLayoutEffect(() => {
1801
- const handleResize = debounce(interval, () => setDimensions({
1802
- width: window.innerWidth,
1803
- height: window.innerHeight
1804
- }));
1801
+ const updateDimensions = () => {
1802
+ const { innerWidth: width, innerHeight: height } = window;
1803
+ setDimensions((prev) => prev.width === width && prev.height === height ? prev : {
1804
+ width,
1805
+ height
1806
+ });
1807
+ };
1808
+ const handleResize = debounce(interval, updateDimensions);
1809
+ updateDimensions();
1805
1810
  window.addEventListener("resize", handleResize);
1806
- return () => window.removeEventListener("resize", handleResize);
1811
+ return () => {
1812
+ window.removeEventListener("resize", handleResize);
1813
+ handleResize.cancel();
1814
+ };
1807
1815
  }, [interval]);
1808
1816
  return dimensions;
1809
1817
  };