@@ -302,23 +302,26 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
302302
303303 useImperativeHandle ( ref , ( ) => ( { checkUnsaveChanges } ) , [ checkUnsaveChanges ] )
304304
305- const onConfirmDialogResult = useCallback ( ( confirm : boolean ) => {
306- if ( confirm ) {
307- confirmDialogHandler . current ?.( )
308- }
309- } , [ ] )
305+ const onConfirmDialogResult = useCallback (
306+ ( confirm : boolean ) => {
307+ if ( confirm ) {
308+ // Discard changes: Reset state and flag
309+ setCachedState ( extensionState ) // Revert to original state
310+ setChangeDetected ( false ) // Reset change flag
311+ confirmDialogHandler . current ?.( ) // Execute the pending action (e.g., tab switch)
312+ }
313+ // If confirm is false (Cancel), do nothing, dialog closes automatically
314+ } ,
315+ [ extensionState ] , // Depend on extensionState to get the latest original state
316+ )
310317
311318 // Handle tab changes with unsaved changes check
312319 const handleTabChange = useCallback (
313320 ( newTab : SectionName ) => {
314- if ( isChangeDetected ) {
315- confirmDialogHandler . current = ( ) => setActiveTab ( newTab )
316- setDiscardDialogShow ( true )
317- } else {
318- setActiveTab ( newTab )
319- }
321+ // Directly switch tab without checking for unsaved changes
322+ setActiveTab ( newTab )
320323 } ,
321- [ isChangeDetected ] ,
324+ [ ] , // No dependency on isChangeDetected needed anymore
322325 )
323326
324327 // Store direct DOM element refs for each tab
0 commit comments