Skip to content

Commit f3487f1

Browse files
committed
1.1.7 - fixes the build with a ModalTrigger ssr:false adjustment
1 parent f2b46e0 commit f3487f1

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

components/ModalStack.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const ModalStack: React.FC<ModalStackProps> = () => {
1818
{modalStack.map((modalState, index) => {
1919
const { key, component: ModalComponent, props } = modalState;
2020

21+
if (!ModalComponent) {
22+
console.warn(`ModalComponent is undefined for modal with key: ${key}`);
23+
return null;
24+
}
25+
2126
const offsetFromLast = totalModals - 1 - index;
2227
const translateY = -offsetFromLast * 40;
2328
const blur = offsetFromLast * 1.1;

components/ModalTrigger.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

33
import * as React from 'react';
4+
import dynamic from 'next/dynamic';
45

56
import { useModals } from '@components/page/ModalContext';
67

@@ -10,16 +11,28 @@ interface ModalTriggerProps {
1011
modalProps?: Record<string, any>;
1112
}
1213

13-
function ModalTrigger({ children, modal, modalProps = {} }: ModalTriggerProps) {
14+
const ModalTriggerClient = dynamic(() => Promise.resolve(ModalTriggerImpl), {
15+
ssr: false,
16+
});
17+
18+
function ModalTriggerImpl({ children, modal, modalProps = {} }: ModalTriggerProps) {
1419
const { open } = useModals();
1520

1621
const onHandleOpenModal = () => {
17-
open(modal, modalProps);
22+
if (modal && typeof modal === 'function') {
23+
open(modal, modalProps);
24+
} else {
25+
console.warn('ModalTrigger: modal prop is not a valid component', modal);
26+
}
1827
};
1928

2029
return React.cloneElement(children, {
2130
onClick: onHandleOpenModal,
2231
});
2332
}
2433

34+
function ModalTrigger(props: ModalTriggerProps) {
35+
return <ModalTriggerClient {...props} />;
36+
}
37+
2538
export default ModalTrigger;

components/page/ModalContext.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export const ModalProvider: React.FC<{ children: React.ReactNode }> = ({ childre
2020
const [modalStack, setModalStack] = React.useState<ModalState<any>[]>([]);
2121

2222
const open = <P,>(component: ModalComponent<P>, props: P): string => {
23+
if (!component || typeof component !== 'function') {
24+
console.error('ModalContext: Invalid component provided to open()', component);
25+
return '';
26+
}
27+
2328
const key = `modal-${Date.now()}-${Math.random()}`;
2429

2530
const newModal: ModalState<P> = { key, component, props };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"node": ">=18"
66
},
77
"license": "MIT",
8-
"version": "1.1.6",
8+
"version": "1.1.7",
99
"scripts": {
1010
"dev": "next -p 10000",
1111
"build": "next build",

0 commit comments

Comments
 (0)