Hi. I have encounter a wired behaviour that I have an array of steps in JSON format being saved in the database. For persisting the steps I have a validation check that will load all steps from the database and call step.apply for all past steps and the incoming steps.
For unknown reason, I encounter that for the same set of steps, the validation passed without error. But later on will have exception throw when calling step.apply.
Nope, that shouldn’t happen (applying steps is a pure operation, and applying the same step to the same document should give the same result). You may have some data corruption somewhere—for example accidental mutation of an object or array that is shared between data structures because it is supposed to be immutable.
If you can reduce the issue to a minimal example, that might help.
Merging steps should generally be safe, if you can make sure that the document versions between the merged steps aren’t going to be used (which can be tricky to do with collaborative editing). If you find a sequence of steps that is valid individually, but can’t be applied when merged, let me know, since that would be a bug.
Thanks for the test case. It did indeed have to do with the structure flag—you hit a rare case where two structure-changing steps merged into a step that couldn’t actually be applied anymore. This patch should prevent such merging from happening (released as prosemirror-transform 1.2.12).