File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,13 @@ export function ContextMenuProvider({
2424 // Check if there's already a parent context menu provider
2525 const parentContext = useContext ( Context ) ;
2626
27+ // Prevent accidental nested providers
28+ if ( parentContext ) {
29+ throw new Error (
30+ 'Duplicated ContextMenuProvider found. Please remove the nested provider.'
31+ ) ;
32+ }
33+
2734 const [ menu , setMenu ] = useState < ContextMenuState > ( {
2835 isOpen : false ,
2936 itemGroups : [ ] ,
@@ -41,11 +48,6 @@ export function ContextMenuProvider({
4148 ) ;
4249
4350 useEffect ( ( ) => {
44- // If there's a parent provider, don't add event listeners
45- if ( parentContext ) {
46- return ;
47- }
48-
4951 function handleContextMenu ( event : MouseEvent ) {
5052 event . preventDefault ( ) ;
5153
@@ -73,7 +75,7 @@ export function ContextMenuProvider({
7375 document . removeEventListener ( 'contextmenu' , handleContextMenu ) ;
7476 window . removeEventListener ( 'resize' , handleClosingEvent ) ;
7577 } ;
76- } , [ handleClosingEvent , parentContext ] ) ;
78+ } , [ handleClosingEvent ] ) ;
7779
7880 const value = useMemo (
7981 ( ) => ( {
@@ -82,13 +84,6 @@ export function ContextMenuProvider({
8284 [ close ]
8385 ) ;
8486
85- // Prevent accidental nested providers
86- if ( parentContext ) {
87- throw new Error (
88- 'Duplicated ContextMenuProvider found. Please remove the nested provider.'
89- ) ;
90- }
91-
9287 const Wrapper = wrapper ?? React . Fragment ;
9388
9489 return (
You can’t perform that action at this time.
0 commit comments