@skyscanner/backpack-web 31.3.1 → 31.4.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.
@@ -19,6 +19,7 @@
19
19
  import { useState, useEffect } from 'react';
20
20
  import { createPortal } from 'react-dom';
21
21
  import withScrim from "./withScrim";
22
+ import BpkScrim from "./BpkScrim";
22
23
  import { jsx as _jsx } from "react/jsx-runtime";
23
24
  const getPortalElement = target => {
24
25
  const portalElement = target && typeof target === 'function' ? target() : null;
@@ -28,7 +29,7 @@ const getPortalElement = target => {
28
29
  if (document.body) {
29
30
  return document.body;
30
31
  }
31
- throw new Error('Render target and fallback unavailable');
32
+ throw new Error('Render target and fallback unavailable.');
32
33
  };
33
34
  const withScrimmedPortal = WrappedComponent => {
34
35
  const Scrimmed = withScrim(WrappedComponent);
@@ -36,15 +37,29 @@ const withScrimmedPortal = WrappedComponent => {
36
37
  renderTarget,
37
38
  ...rest
38
39
  }) => {
39
- const portalElement = getPortalElement(renderTarget);
40
40
  const [isPortalReady, setIsPortalReady] = useState(false);
41
41
  useEffect(() => {
42
42
  setIsPortalReady(true);
43
43
  }, []);
44
- return /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(Scrimmed, {
45
- ...rest,
46
- isPortalReady: isPortalReady
47
- }), portalElement);
44
+
45
+ /**
46
+ * The following code runs only on the client - only once the component has been mounted.
47
+ */
48
+ if (isPortalReady) {
49
+ const portalElement = getPortalElement(renderTarget);
50
+ return /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(Scrimmed, {
51
+ ...rest,
52
+ isPortalReady: isPortalReady
53
+ }), portalElement);
54
+ }
55
+
56
+ /**
57
+ * The following code will run on both server and on the intial render on the client.
58
+ * This is to ensure the snapshotted markup (initial render before the component has been mounted) is the same on both server and client.
59
+ * This is the recommended approach from React for those cases that require rendering something different on the server and the client
60
+ * https://react.dev/reference/react-dom/hydrate#handling-different-client-and-server-content
61
+ */
62
+ return /*#__PURE__*/_jsx(BpkScrim, {});
48
63
  };
49
64
  return ScrimmedComponent;
50
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyscanner/backpack-web",
3
- "version": "31.3.1",
3
+ "version": "31.4.0",
4
4
  "description": "Backpack Design System web library",
5
5
  "repository": {
6
6
  "type": "git",