@@ -160,26 +160,18 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
160
160
} , [ searchValue ] ) ;
161
161
162
162
// ========================= Disabled =========================
163
- const disabledCacheRef = React . useRef < Map < string , boolean > > ( new Map ( ) ) ;
163
+ // Cache disabled states in React state to ensure re-render when cache updates
164
+ const [ disabledCache , setDisabledCache ] = React . useState < Map < string , boolean > > ( new Map ( ) ) ;
164
165
165
- // Force update is needed since clearing cache alone doesn't trigger
166
- // a recalculation of node disabled states
167
- const [ , setForceUpdate ] = React . useState ( { } ) ;
168
-
169
- // When leftMaxCount changes, we need to:
170
- // 1. Clear the disabled state cache
171
- // 2. Trigger a re-render to recalculate all node disabled states
172
- // This ensures parent nodes are properly disabled when max count is reached
173
166
React . useEffect ( ( ) => {
174
167
if ( leftMaxCount ) {
175
- disabledCacheRef . current . clear ( ) ;
176
- setForceUpdate ( { } ) ;
168
+ setDisabledCache ( new Map ( ) ) ;
177
169
}
178
170
} , [ leftMaxCount ] ) ;
179
171
180
172
function getDisabledWithCache ( node : DataNode ) {
181
173
const value = node [ fieldNames . value ] ;
182
- if ( ! disabledCacheRef . current . has ( value ) ) {
174
+ if ( ! disabledCache . has ( value ) ) {
183
175
const entity = valueEntities . get ( value ) ;
184
176
const isLeaf = ( entity . children || [ ] ) . length === 0 ;
185
177
@@ -192,12 +184,16 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
192
184
) ;
193
185
194
186
const checkableChildrenCount = checkableChildren . length ;
195
- disabledCacheRef . current . set ( value , checkableChildrenCount > leftMaxCount ) ;
187
+ const newCache = new Map ( disabledCache ) ;
188
+ newCache . set ( value , checkableChildrenCount > leftMaxCount ) ;
189
+ setDisabledCache ( newCache ) ;
196
190
} else {
197
- disabledCacheRef . current . set ( value , false ) ;
191
+ const newCache = new Map ( disabledCache ) ;
192
+ newCache . set ( value , false ) ;
193
+ setDisabledCache ( newCache ) ;
198
194
}
199
195
}
200
- return disabledCacheRef . current . get ( value ) ;
196
+ return disabledCache . get ( value ) ;
201
197
}
202
198
203
199
const nodeDisabled = useEvent ( ( node : DataNode ) => {
0 commit comments