diff --git a/extensions/plugin-history-sync/src/historyState.ts b/extensions/plugin-history-sync/src/historyState.ts index ae57b68e..1c7342ce 100644 --- a/extensions/plugin-history-sync/src/historyState.ts +++ b/extensions/plugin-history-sync/src/historyState.ts @@ -6,7 +6,6 @@ const STATE_TAG = `@stackflow/plugin-history-sync`; interface State { activity: Activity; step?: ActivityStep; - silent?: boolean; } interface SerializedState extends State { @@ -45,7 +44,6 @@ function serializeState(state: State): SerializedState { _TAG: STATE_TAG, activity: serializeActivity(state.activity), step: state.step ? serializeStep(state.step) : undefined, - silent: state.silent, }; } diff --git a/extensions/plugin-history-sync/src/historySyncPlugin.tsx b/extensions/plugin-history-sync/src/historySyncPlugin.tsx index 63e8de75..cf3d22b0 100644 --- a/extensions/plugin-history-sync/src/historySyncPlugin.tsx +++ b/extensions/plugin-history-sync/src/historySyncPlugin.tsx @@ -47,7 +47,7 @@ export function historySyncPlugin< return () => { let pushFlag = 0; - let popFlag = 0; + let silentFlag = false; const { enqueue } = makeHistoryTaskQueue(history); @@ -174,8 +174,8 @@ export function historySyncPlugin< ); const onPopState: Listener = (e) => { - if (popFlag) { - popFlag -= 1; + if (silentFlag) { + silentFlag = false; return; } @@ -188,12 +188,6 @@ export function historySyncPlugin< const targetActivity = historyState.activity; const targetActivityId = historyState.activity.id; const targetStep = historyState.step; - const { silent } = historyState; - - if (silent) { - historyState.silent = false; - return; - } const { activities } = getStack(); const currentActivity = activities.find( @@ -321,17 +315,17 @@ export function historySyncPlugin< options.urlPatternOptions, ); - enqueue(() => + enqueue(() => { + silentFlag = true; pushState({ history, pathname: template.fill(activity.params), state: { activity, - silent: true, }, useHash: options.useHash, - }), - ); + }); + }); }, onStepPushed({ effect: { activity, step } }) { if (pushFlag) { @@ -344,18 +338,18 @@ export function historySyncPlugin< options.urlPatternOptions, ); - enqueue(() => + enqueue(() => { + silentFlag = true; pushState({ history, pathname: template.fill(activity.params), state: { activity, step, - silent: true, }, useHash: options.useHash, - }), - ); + }); + }); }, onReplaced({ effect: { activity } }) { if (!activity.isActive) { @@ -367,17 +361,17 @@ export function historySyncPlugin< options.urlPatternOptions, ); - enqueue(() => + enqueue(() => { + silentFlag = true; replaceState({ history, pathname: template.fill(activity.params), state: { activity, - silent: true, }, useHash: options.useHash, - }), - ); + }); + }); }, onStepReplaced({ effect: { activity, step } }) { if (!activity.isActive) { @@ -389,18 +383,18 @@ export function historySyncPlugin< options.urlPatternOptions, ); - enqueue(() => + enqueue(() => { + silentFlag = true; replaceState({ history, pathname: template.fill(activity.params), state: { activity, step, - silent: true, }, useHash: options.useHash, - }), - ); + }); + }); }, onBeforePush({ actionParams, actions: { overrideActionParams } }) { const template = makeTemplate( @@ -451,7 +445,7 @@ export function historySyncPlugin< for (let i = 0; i < previousActivity.steps.length - 1; i += 1) { // eslint-disable-next-line no-loop-func enqueue(() => { - popFlag += 1; + silentFlag = true; history.back(); }); } @@ -466,7 +460,7 @@ export function historySyncPlugin< if ((currentActivity?.steps.length ?? 0) > 1) { enqueue(() => { - popFlag += 1; + silentFlag = true; history.back(); }); } @@ -486,7 +480,7 @@ export function historySyncPlugin< for (let i = 0; i < popCount; i += 1) { // eslint-disable-next-line no-loop-func enqueue(() => { - popFlag += 1; + silentFlag = true; history.back(); }); }