File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { environmentKeys } from '@/hooks/queries/environment'
66import { useExecutionStore } from '@/stores/execution'
77import { useMothershipDraftsStore } from '@/stores/mothership-drafts/store'
88import { consolePersistence , useTerminalConsoleStore } from '@/stores/terminal'
9+ import { clearPersistedUndoRedo } from '@/stores/undo-redo/storage'
910import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
1011import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1112import { useWorkflowStore } from '@/stores/workflows/workflow/store'
@@ -55,6 +56,9 @@ export async function clearUserData(): Promise<void> {
5556 const keysToRemove = Object . keys ( localStorage ) . filter ( ( key ) => ! keysToKeep . includes ( key ) )
5657 keysToRemove . forEach ( ( key ) => localStorage . removeItem ( key ) )
5758
59+ // Persisted undo/redo lives in IndexedDB; remove it as well.
60+ await clearPersistedUndoRedo ( )
61+
5862 logger . info ( 'User data cleared successfully' )
5963 } catch ( error ) {
6064 logger . error ( 'Error clearing user data:' , { error } )
Original file line number Diff line number Diff line change @@ -154,4 +154,34 @@ describe('undo-redo IndexedDB storage adapter', () => {
154154 expect ( value ) . toBeNull ( )
155155 } )
156156 } )
157+
158+ describe ( 'clearPersistedUndoRedo' , ( ) => {
159+ it ( 'deletes the undo-redo key from IndexedDB' , async ( ) => {
160+ const { clearPersistedUndoRedo, migrationReady } = await loadFreshModule ( )
161+ await migrationReady
162+ idbStore . set ( STORE_KEY , 'present' )
163+
164+ await clearPersistedUndoRedo ( )
165+
166+ expect ( idbStore . has ( STORE_KEY ) ) . toBe ( false )
167+ } )
168+
169+ it ( 'leaves the migration flag intact so migration does not re-run' , async ( ) => {
170+ const { clearPersistedUndoRedo, migrationReady } = await loadFreshModule ( )
171+ await migrationReady
172+ idbStore . set ( STORE_KEY , 'present' )
173+
174+ await clearPersistedUndoRedo ( )
175+
176+ expect ( idbStore . get ( MIGRATION_KEY ) ) . toBe ( true )
177+ } )
178+
179+ it ( 'swallows IndexedDB errors so sign-out does not crash' , async ( ) => {
180+ const { clearPersistedUndoRedo, migrationReady } = await loadFreshModule ( )
181+ await migrationReady
182+
183+ idbDel . mockRejectedValueOnce ( new Error ( 'idb delete failed' ) )
184+ await expect ( clearPersistedUndoRedo ( ) ) . resolves . toBeUndefined ( )
185+ } )
186+ } )
157187} )
Original file line number Diff line number Diff line change @@ -55,6 +55,23 @@ async function awaitMigration(): Promise<void> {
5555 }
5656}
5757
58+ /**
59+ * Removes the persisted undo/redo payload from IndexedDB.
60+ *
61+ * Called from `clearUserData` on sign-out so undo history does not
62+ * survive across user sessions on the same device.
63+ */
64+ export async function clearPersistedUndoRedo ( ) : Promise < void > {
65+ if ( typeof window === 'undefined' ) return
66+ await awaitMigration ( )
67+
68+ try {
69+ await del ( STORE_KEY )
70+ } catch ( error ) {
71+ logger . warn ( 'Failed to clear persisted undo-redo' , { error } )
72+ }
73+ }
74+
5875export const indexedDBStorage : StateStorage = {
5976 getItem : async ( name : string ) : Promise < string | null > => {
6077 if ( typeof window === 'undefined' ) return null
You can’t perform that action at this time.
0 commit comments