+
+
+ );
+ };
+ render();
+ expect(await screen.findByText("Modal Content")).toBeInTheDocument();
+ });
+
it("shows a modal when clicking on the button", async () => {
const Wrapper = () => {
const modal = useModal();
diff --git a/packages/react/src/components/Modal/index.tsx b/packages/react/src/components/Modal/index.tsx
index 0b4bcb7..548567a 100644
--- a/packages/react/src/components/Modal/index.tsx
+++ b/packages/react/src/components/Modal/index.tsx
@@ -52,6 +52,23 @@ export interface ModalProps
}> {}
export const Modal = (props: ModalProps) => {
+ /**
+ * This is a workaround to prevent the modal from rendering on the first render because if the modal is open on the
+ * first render, it will not be able to resolve document.getElementById("c__modals-portal") which is not rendered yet.
+ */
+ const [firstRender, setFirstRender] = React.useState(true);
+ useEffect(() => {
+ setFirstRender(false);
+ }, []);
+
+ if (firstRender) {
+ return null;
+ }
+
+ return ;
+};
+
+export const ModalInner = (props: ModalProps) => {
const ref = React.useRef(null);
useEffect(() => {