cozy-ui 140.6.0 → 141.0.0

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,3 +1,16 @@
1
+ # [141.0.0](https://github.com/cozy/cozy-ui/compare/v140.6.0...v141.0.0) (2026-07-30)
2
+
3
+
4
+ * fix(breakpoints)!: target the requesting iframe ([b222ae2](https://github.com/cozy/cozy-ui/commit/b222ae2)), closes [#2949](https://github.com/cozy/cozy-ui/issues/2949)
5
+
6
+
7
+ ### BREAKING CHANGES
8
+
9
+ * replace the old hook usage with:
10
+
11
+ const { iframeWindow } = useIframeConnection({ parentBasedIframe })
12
+ useIframeToSendWidth({ iframeWindow })
13
+
1
14
  # [140.6.0](https://github.com/cozy/cozy-ui/compare/v140.5.2...v140.6.0) (2026-07-29)
2
15
 
3
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "140.6.0",
3
+ "version": "141.0.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "engines": {
6
6
  "node": "24.x"
@@ -13,8 +13,8 @@ export const BreakpointsProvider = ({ parentBasedIframe, children }) => {
13
13
  const [breakpoints, setBreakpoints] = useState(
14
14
  getBreakpointsStatus(breakpointDefs)
15
15
  )
16
- const { hasIframe } = useIframeConnection({ parentBasedIframe })
17
- useIframeToSendWidth({ hasIframe })
16
+ const { iframeWindow } = useIframeConnection({ parentBasedIframe })
17
+ useIframeToSendWidth({ iframeWindow })
18
18
  const { parentBreakpoints } = useParentBreakpoints({ parentBasedIframe })
19
19
 
20
20
  useEffect(() => {
@@ -0,0 +1,27 @@
1
+ import { act, render } from '@testing-library/react'
2
+ import React from 'react'
3
+
4
+ import { BreakpointsProvider } from './index'
5
+
6
+ it('sends parent breakpoints to the requesting iframe', () => {
7
+ const iframeWindow = { postMessage: jest.fn() }
8
+ const message = new MessageEvent('message', {
9
+ data: 'UI-breakpoints-needParentBreakpoints'
10
+ })
11
+ Object.defineProperty(message, 'source', { value: iframeWindow })
12
+
13
+ render(
14
+ <BreakpointsProvider>
15
+ <div />
16
+ </BreakpointsProvider>
17
+ )
18
+
19
+ act(() => {
20
+ window.dispatchEvent(message)
21
+ })
22
+
23
+ expect(iframeWindow.postMessage).toHaveBeenCalledWith(
24
+ `UI-breakpoints-value:${window.innerWidth}`,
25
+ '*'
26
+ )
27
+ })
@@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'
3
3
  import { isInsideIframe } from '../../helpers/breakpoints'
4
4
 
5
5
  export const useIframeConnection = ({ parentBasedIframe }) => {
6
- const [hasIframe, setHasIframe] = useState(false)
6
+ const [iframeWindow, setIframeWindow] = useState(null)
7
7
 
8
8
  const isIframe = parentBasedIframe && isInsideIframe()
9
9
 
@@ -11,7 +11,7 @@ export const useIframeConnection = ({ parentBasedIframe }) => {
11
11
  useEffect(() => {
12
12
  const handleMessage = ev => {
13
13
  if (ev.data === 'UI-breakpoints-needParentBreakpoints') {
14
- setHasIframe(true)
14
+ setIframeWindow(ev.source)
15
15
  }
16
16
  }
17
17
 
@@ -27,5 +27,5 @@ export const useIframeConnection = ({ parentBasedIframe }) => {
27
27
  }
28
28
  }, [isIframe])
29
29
 
30
- return { hasIframe }
30
+ return { iframeWindow }
31
31
  }
@@ -1,27 +1,19 @@
1
1
  import throttle from 'lodash/throttle'
2
2
  import { useEffect } from 'react'
3
3
 
4
- /**
5
- * To send window innerWidth to first iframe
6
- * @returns
7
- */
8
- const sendWidthToIframe = () =>
9
- window.frames[1].postMessage(`UI-breakpoints-value:${window.innerWidth}`, '*')
4
+ const sendWidthToIframe = iframeWindow =>
5
+ iframeWindow?.postMessage(`UI-breakpoints-value:${window.innerWidth}`, '*')
10
6
 
11
- export const useIframeToSendWidth = ({ hasIframe }) => {
7
+ export const useIframeToSendWidth = ({ iframeWindow }) => {
12
8
  // parent window send its innerWidth
13
9
  useEffect(() => {
14
- if (hasIframe) {
15
- sendWidthToIframe()
16
- }
17
- }, [hasIframe])
10
+ sendWidthToIframe(iframeWindow)
11
+ }, [iframeWindow])
18
12
 
19
13
  // parent window send its innerWidth on resize
20
14
  useEffect(() => {
21
15
  const handleResize = throttle(() => {
22
- if (hasIframe) {
23
- sendWidthToIframe()
24
- }
16
+ sendWidthToIframe(iframeWindow)
25
17
  }, 100)
26
18
 
27
19
  window.addEventListener('resize', handleResize)
@@ -29,5 +21,5 @@ export const useIframeToSendWidth = ({ hasIframe }) => {
29
21
  return () => {
30
22
  window.removeEventListener('resize', handleResize)
31
23
  }
32
- }, [hasIframe])
24
+ }, [iframeWindow])
33
25
  }
@@ -19,10 +19,10 @@ export var BreakpointsProvider = function BreakpointsProvider(_ref) {
19
19
  var _useIframeConnection = useIframeConnection({
20
20
  parentBasedIframe: parentBasedIframe
21
21
  }),
22
- hasIframe = _useIframeConnection.hasIframe;
22
+ iframeWindow = _useIframeConnection.iframeWindow;
23
23
 
24
24
  useIframeToSendWidth({
25
- hasIframe: hasIframe
25
+ iframeWindow: iframeWindow
26
26
  });
27
27
 
28
28
  var _useParentBreakpoints = useParentBreakpoints({
@@ -1,5 +1,5 @@
1
1
  export function useIframeConnection({ parentBasedIframe }: {
2
2
  parentBasedIframe: any;
3
3
  }): {
4
- hasIframe: boolean;
4
+ iframeWindow: null;
5
5
  };
@@ -4,17 +4,17 @@ import { isInsideIframe } from "cozy-ui/transpiled/react/helpers/breakpoints";
4
4
  export var useIframeConnection = function useIframeConnection(_ref) {
5
5
  var parentBasedIframe = _ref.parentBasedIframe;
6
6
 
7
- var _useState = useState(false),
7
+ var _useState = useState(null),
8
8
  _useState2 = _slicedToArray(_useState, 2),
9
- hasIframe = _useState2[0],
10
- setHasIframe = _useState2[1];
9
+ iframeWindow = _useState2[0],
10
+ setIframeWindow = _useState2[1];
11
11
 
12
12
  var isIframe = parentBasedIframe && isInsideIframe(); // parent window receives from iframe to give breakpoints
13
13
 
14
14
  useEffect(function () {
15
15
  var handleMessage = function handleMessage(ev) {
16
16
  if (ev.data === 'UI-breakpoints-needParentBreakpoints') {
17
- setHasIframe(true);
17
+ setIframeWindow(ev.source);
18
18
  }
19
19
  };
20
20
 
@@ -30,6 +30,6 @@ export var useIframeConnection = function useIframeConnection(_ref) {
30
30
  }
31
31
  }, [isIframe]);
32
32
  return {
33
- hasIframe: hasIframe
33
+ iframeWindow: iframeWindow
34
34
  };
35
35
  };
@@ -1,3 +1,3 @@
1
- export function useIframeToSendWidth({ hasIframe }: {
2
- hasIframe: any;
1
+ export function useIframeToSendWidth({ iframeWindow }: {
2
+ iframeWindow: any;
3
3
  }): void;
@@ -1,32 +1,24 @@
1
1
  import throttle from 'lodash/throttle';
2
2
  import { useEffect } from 'react';
3
- /**
4
- * To send window innerWidth to first iframe
5
- * @returns
6
- */
7
3
 
8
- var sendWidthToIframe = function sendWidthToIframe() {
9
- return window.frames[1].postMessage("UI-breakpoints-value:".concat(window.innerWidth), '*');
4
+ var sendWidthToIframe = function sendWidthToIframe(iframeWindow) {
5
+ return iframeWindow === null || iframeWindow === void 0 ? void 0 : iframeWindow.postMessage("UI-breakpoints-value:".concat(window.innerWidth), '*');
10
6
  };
11
7
 
12
8
  export var useIframeToSendWidth = function useIframeToSendWidth(_ref) {
13
- var hasIframe = _ref.hasIframe;
9
+ var iframeWindow = _ref.iframeWindow;
14
10
  // parent window send its innerWidth
15
11
  useEffect(function () {
16
- if (hasIframe) {
17
- sendWidthToIframe();
18
- }
19
- }, [hasIframe]); // parent window send its innerWidth on resize
12
+ sendWidthToIframe(iframeWindow);
13
+ }, [iframeWindow]); // parent window send its innerWidth on resize
20
14
 
21
15
  useEffect(function () {
22
16
  var handleResize = throttle(function () {
23
- if (hasIframe) {
24
- sendWidthToIframe();
25
- }
17
+ sendWidthToIframe(iframeWindow);
26
18
  }, 100);
27
19
  window.addEventListener('resize', handleResize);
28
20
  return function () {
29
21
  window.removeEventListener('resize', handleResize);
30
22
  };
31
- }, [hasIframe]);
23
+ }, [iframeWindow]);
32
24
  };