diff --git a/core/src/makeCoreStore.ts b/core/src/makeCoreStore.ts index cbdc99aaa..2c35e1086 100644 --- a/core/src/makeCoreStore.ts +++ b/core/src/makeCoreStore.ts @@ -121,9 +121,20 @@ export function makeCoreStore(options: MakeCoreStoreOptions): CoreStore { }; const setStackValue = (nextStackValue: Stack) => { - const effects = produceEffects(stack.value, nextStackValue); + const prevStackValue = stack.value; + const isEventOrderBroken = prevStackValue.events.some( + ({ id }, index) => id !== nextStackValue.events[index].id, + ); + stack.value = nextStackValue; - triggerPostEffectHooks(effects, pluginInstances, actions); + + if (isEventOrderBroken) return; + + triggerPostEffectHooks( + produceEffects(prevStackValue, nextStackValue), + pluginInstances, + actions, + ); }; // Initialize action methods after actions object is fully created diff --git a/extensions/plugin-history-sync/src/historySyncPlugin.tsx b/extensions/plugin-history-sync/src/historySyncPlugin.tsx index 507473121..c9e8bed34 100644 --- a/extensions/plugin-history-sync/src/historySyncPlugin.tsx +++ b/extensions/plugin-history-sync/src/historySyncPlugin.tsx @@ -430,10 +430,7 @@ export function historySyncPlugin< }; if (isBackward()) { - dispatchEvent("Popped", {}); - if (!nextActivity) { - pushFlag += 1; push({ ...targetActivity.enteredBy, }); @@ -443,12 +440,14 @@ export function historySyncPlugin< targetStep?.enteredBy.name === "StepReplaced" ) { const { enteredBy } = targetStep; - pushFlag += 1; + stepPush({ ...enteredBy, }); } } + + dispatchEvent("Popped", {}); } if (isStepBackward()) { if ( @@ -459,7 +458,6 @@ export function historySyncPlugin< ) { const { enteredBy } = targetStep; - pushFlag += 1; stepPush({ ...enteredBy, });