@@ -32,6 +32,19 @@ import { findAllDescendantNodes, isBlockProtected } from '@/stores/workflows/wor
3232
3333const logger = createLogger ( 'CollaborativeWorkflow' )
3434
35+ function parseUndoRedoStackKey ( key : string ) : { workflowId : string ; userId : string } | null {
36+ const separatorIndex = key . indexOf ( ':' )
37+
38+ if ( separatorIndex <= 0 || separatorIndex === key . length - 1 ) {
39+ return null
40+ }
41+
42+ return {
43+ workflowId : key . slice ( 0 , separatorIndex ) ,
44+ userId : key . slice ( separatorIndex + 1 ) ,
45+ }
46+ }
47+
3548export function useCollaborativeWorkflow ( ) {
3649 const undoRedo = useUndoRedo ( )
3750 const isUndoRedoInProgress = useRef ( false )
@@ -239,9 +252,9 @@ export function useCollaborativeWorkflow() {
239252 const undoRedoStore = useUndoRedoStore . getState ( )
240253 const stackKeys = Object . keys ( undoRedoStore . stacks )
241254 stackKeys . forEach ( ( key ) => {
242- const [ wfId , uId ] = key . split ( ':' )
243- if ( wfId === activeWorkflowId ) {
244- undoRedoStore . pruneInvalidEntries ( wfId , uId , graph )
255+ const parsedKey = parseUndoRedoStackKey ( key )
256+ if ( parsedKey ?. workflowId === activeWorkflowId ) {
257+ undoRedoStore . pruneInvalidEntries ( parsedKey . workflowId , parsedKey . userId , graph )
245258 }
246259 } )
247260 }
@@ -281,9 +294,9 @@ export function useCollaborativeWorkflow() {
281294 const undoRedoStore = useUndoRedoStore . getState ( )
282295 const stackKeys = Object . keys ( undoRedoStore . stacks )
283296 stackKeys . forEach ( ( key ) => {
284- const [ wfId , uId ] = key . split ( ':' )
285- if ( wfId === activeWorkflowId ) {
286- undoRedoStore . pruneInvalidEntries ( wfId , uId , graph )
297+ const parsedKey = parseUndoRedoStackKey ( key )
298+ if ( parsedKey ?. workflowId === activeWorkflowId ) {
299+ undoRedoStore . pruneInvalidEntries ( parsedKey . workflowId , parsedKey . userId , graph )
287300 }
288301 } )
289302
@@ -646,10 +659,12 @@ export function useCollaborativeWorkflow() {
646659 const undoRedoStore = useUndoRedoStore . getState ( )
647660 const stackKeys = Object . keys ( undoRedoStore . stacks )
648661 stackKeys . forEach ( ( key ) => {
649- const [ wfId , userId ] = key . split ( ':' )
650- if ( wfId = == workflowId ) {
651- undoRedoStore . pruneInvalidEntries ( wfId , userId , graph )
662+ const parsedKey = parseUndoRedoStackKey ( key )
663+ if ( ! parsedKey || parsedKey . workflowId ! == workflowId ) {
664+ return
652665 }
666+
667+ undoRedoStore . pruneInvalidEntries ( parsedKey . workflowId , parsedKey . userId , graph )
653668 } )
654669 } finally {
655670 isApplyingRemoteChange . current = false
0 commit comments