File tree Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ const ModalStack: React.FC<ModalStackProps> = () => {
18
18
{ modalStack . map ( ( modalState , index ) => {
19
19
const { key, component : ModalComponent , props } = modalState ;
20
20
21
+ if ( ! ModalComponent ) {
22
+ console . warn ( `ModalComponent is undefined for modal with key: ${ key } ` ) ;
23
+ return null ;
24
+ }
25
+
21
26
const offsetFromLast = totalModals - 1 - index ;
22
27
const translateY = - offsetFromLast * 40 ;
23
28
const blur = offsetFromLast * 1.1 ;
Original file line number Diff line number Diff line change 1
1
'use client' ;
2
2
3
3
import * as React from 'react' ;
4
+ import dynamic from 'next/dynamic' ;
4
5
5
6
import { useModals } from '@components/page/ModalContext' ;
6
7
@@ -10,16 +11,28 @@ interface ModalTriggerProps {
10
11
modalProps ?: Record < string , any > ;
11
12
}
12
13
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 ) {
14
19
const { open } = useModals ( ) ;
15
20
16
21
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
+ }
18
27
} ;
19
28
20
29
return React . cloneElement ( children , {
21
30
onClick : onHandleOpenModal ,
22
31
} ) ;
23
32
}
24
33
34
+ function ModalTrigger ( props : ModalTriggerProps ) {
35
+ return < ModalTriggerClient { ...props } /> ;
36
+ }
37
+
25
38
export default ModalTrigger ;
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ export const ModalProvider: React.FC<{ children: React.ReactNode }> = ({ childre
20
20
const [ modalStack , setModalStack ] = React . useState < ModalState < any > [ ] > ( [ ] ) ;
21
21
22
22
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
+
23
28
const key = `modal-${ Date . now ( ) } -${ Math . random ( ) } ` ;
24
29
25
30
const newModal : ModalState < P > = { key, component, props } ;
Original file line number Diff line number Diff line change 5
5
"node" : " >=18"
6
6
},
7
7
"license" : " MIT" ,
8
- "version" : " 1.1.6 " ,
8
+ "version" : " 1.1.7 " ,
9
9
"scripts" : {
10
10
"dev" : " next -p 10000" ,
11
11
"build" : " next build" ,
You can’t perform that action at this time.
0 commit comments