@@ -214,8 +214,19 @@ export function useHistoryEdit<T extends {}>(
214
214
const current = history . stack [ history . index ]
215
215
const snapshottedCurrent = snapshot . stack [ snapshot . index ]
216
216
217
- // make it a soft checkpoint if the state is unchanged
217
+ const shouldSquash =
218
+ checkpoint . action === current . action &&
219
+ checkpoint . squashBy !== undefined &&
220
+ checkpoint . squashBy === current . squashBy &&
221
+ // only squash if currently on top of the history stack
222
+ history . index === history . stack . length - 1
223
+
224
+ // make it a soft checkpoint if the checkpoint is non-squashable but the state is unchanged,
225
+ // because we don't want the history to advance when the state is unchanged, but still want to
226
+ // prevent the next checkpoint from being squashed since a non-squashable checkpoint is being used
227
+ // and it's supposed to block the squashing even if it's not actually inserted into the history
218
228
if (
229
+ ! shouldSquash &&
219
230
current . state === snapshottedCurrent . state &&
220
231
JSON . stringify ( current . state ) ===
221
232
JSON . stringify ( snapshottedCurrent . state )
@@ -241,13 +252,6 @@ export function useHistoryEdit<T extends {}>(
241
252
}
242
253
}
243
254
244
- const shouldSquash =
245
- checkpoint . action === current . action &&
246
- checkpoint . squashBy !== undefined &&
247
- checkpoint . squashBy === current . squashBy &&
248
- // only squash if currently on top of the history stack
249
- history . index === history . stack . length - 1
250
-
251
255
if ( shouldSquash || checkpoint === softCheckpoint ) {
252
256
const newStack = [
253
257
...history . stack . slice ( 0 , history . index ) ,
0 commit comments