reshaped 3.7.0-canary.10 → 3.7.0-canary.11

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.
@@ -4,6 +4,8 @@ import React from "react";
4
4
  import ReactDOM from "react-dom";
5
5
  import Theme from "../../Theme/index.js";
6
6
  import s from "./Portal.module.css";
7
+ import useIsomorphicLayoutEffect from "../../../hooks/useIsomorphicLayoutEffect.js";
8
+ import useToggle from "../../../hooks/useToggle.js";
7
9
  const PortalScopeContext = React.createContext({});
8
10
  export const usePortalScope = () => {
9
11
  return React.useContext(PortalScopeContext);
@@ -14,6 +16,7 @@ export const usePortalScope = () => {
14
16
  */
15
17
  const Portal = (props) => {
16
18
  const { children, targetRef } = props;
19
+ const mountedToggle = useToggle();
17
20
  const rootRef = React.useRef(null);
18
21
  const rootNode = rootRef.current?.getRootNode();
19
22
  const isShadowDom = rootNode instanceof ShadowRoot;
@@ -28,10 +31,15 @@ const Portal = (props) => {
28
31
  const portal = usePortalScope();
29
32
  const nextScopeRef = targetRef || portal.scopeRef;
30
33
  const targetEl = nextScopeRef?.current || defaultTargetEl;
34
+ useIsomorphicLayoutEffect(() => {
35
+ mountedToggle.activate();
36
+ return () => mountedToggle.deactivate();
37
+ }, []);
31
38
  /* Preserve the current theme when rendered in body */
32
39
  return [
33
40
  ReactDOM.createPortal(_jsx(Theme, { children: children }), targetEl),
34
- _jsx("div", { ref: rootRef, className: s.root }, "root"),
41
+ // Make sure this element doesn't affect components using :last-child when their children use portals
42
+ !mountedToggle.active && _jsx("div", { ref: rootRef, className: s.root }, "root"),
35
43
  ];
36
44
  };
37
45
  function PortalScope(props) {
@@ -28,13 +28,7 @@ const useIsDismissible = (args) => {
28
28
  React.useEffect(() => {
29
29
  if (!active)
30
30
  return;
31
- if (queue.length) {
32
- // Make sure new item is added to the queue after others unmount first
33
- onNextFrame(() => addToQueue(id, contentRef, triggerRef));
34
- }
35
- else {
36
- addToQueue(id, contentRef, triggerRef);
37
- }
31
+ onNextFrame(() => addToQueue(id, contentRef, triggerRef));
38
32
  return () => removeFromQueue(id);
39
33
  }, [active, id, contentRef, triggerRef]);
40
34
  return React.useCallback(() => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reshaped",
3
3
  "description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
4
- "version": "3.7.0-canary.10",
4
+ "version": "3.7.0-canary.11",
5
5
  "license": "MIT",
6
6
  "email": "hello@reshaped.so",
7
7
  "homepage": "https://reshaped.so",