@@ -2,6 +2,7 @@ import CloseIcon from "@mui/icons-material/Close"
22import type { SnackbarKey , SnackbarMessage , VariantType } from "notistack"
33import { useSnackbar } from "notistack"
44import type React from "react"
5+ import { useRef } from "react"
56import { useMemo } from "react"
67import type { FunctionComponent , ReactNode } from "react"
78import { Fragment , useCallback , useReducer , useState } from "react"
@@ -120,6 +121,9 @@ export const UIProvider: React.FC<UIProviderProps> = ({ children }) => {
120121 }
121122 } , [ refreshDep , panels ] )
122123
124+ const blockStateRef = useRef < UIBlockState > ( blockState )
125+ blockStateRef . current = blockState
126+
123127 const openModal : OpenModalFn = useCallback (
124128 < T , P > (
125129 content : FunctionComponent < ModalImplProps < T , P > > ,
@@ -128,8 +132,8 @@ export const UIProvider: React.FC<UIProviderProps> = ({ children }) => {
128132 props : Omit < ModalProps < P > , "type" | "configured" | "custom" > &
129133 Omit < UIScreenCallbacks < T > , "onBeforeAccept" > = DEFAULT_PROPS
130134 ) => {
131- if ( blockState . blocked ) {
132- addToast ( "warning" , blockState . blockMessage )
135+ if ( blockStateRef . current . blocked ) {
136+ addToast ( "warning" , blockStateRef . current . blockMessage )
133137 return null
134138 }
135139
@@ -163,7 +167,7 @@ export const UIProvider: React.FC<UIProviderProps> = ({ children }) => {
163167 setModal ( newModal as Modal < any , any > )
164168 return id
165169 } ,
166- [ modal , blockState ]
170+ [ modal ]
167171 )
168172
169173 const snackbarAction = useCallback (
@@ -215,8 +219,8 @@ export const UIProvider: React.FC<UIProviderProps> = ({ children }) => {
215219 }
216220
217221 // if any (generic) open panel declares itself as blocking, prevent opening a new one
218- if ( blockState . blocked ) {
219- addToast ( "warning" , blockState . blockMessage )
222+ if ( blockStateRef . current . blocked ) {
223+ addToast ( "warning" , blockStateRef . current . blockMessage )
220224 return null
221225 }
222226
@@ -252,7 +256,7 @@ export const UIProvider: React.FC<UIProviderProps> = ({ children }) => {
252256 } )
253257 return id
254258 } ,
255- [ panels , addToast , blockState ]
259+ [ panels , addToast ]
256260 )
257261
258262 const closeModal = useCallback (
@@ -309,15 +313,18 @@ export const UIProvider: React.FC<UIProviderProps> = ({ children }) => {
309313 if ( "exclusiveGroup" in screen . props ) {
310314 const exclusiveGroup = screen . props . exclusiveGroup
311315 if ( exclusiveGroup != null ) {
312- const existing = panels . find ( p => p . props . exclusiveGroup == exclusiveGroup && p !== screen )
313- if ( existing ) {
314- closePanel ( existing . id , CloseType . OVERWRITE )
315- }
316+ setPanels ( panels => {
317+ const existing = panels . find ( p => p . props . exclusiveGroup == exclusiveGroup && p !== screen )
318+ if ( existing ) {
319+ closePanel ( existing . id , CloseType . OVERWRITE )
320+ }
321+ return panels
322+ } )
316323 }
317324 }
318325 refresh ( )
319326 } ,
320- [ closePanel , panels ]
327+ [ closePanel ]
321328 )
322329
323330 return (
0 commit comments