Collab unconfirm with exit steps error

Hi marijn: I met a problem in my work, what i do:

Every client submit its version which get from websoket and its unconfirm steps, that means server version will high then the client version. at the same time, i save all others steps group by clientID.

Then there was a problem, i have no idea how to deal with the unconfirm steps with the others steps.

if (messageArray.length > 0) {
      for (let i = 0; i < messageArray.length; i++) {
        let tempTr: any = flag ? initTr : new Transform(newDoc);
        if (clientID != messageArray[i].clientID) {
          const over = messageArray[i].steps;
          let rebaseResult = rebaseStepsHandle(unconfirm, over, tempTr, cursorCache.from, cursorCache.to);
          unconfirm = rebaseResult.unconfirm;
          newDoc = rebaseResult.doc;
          cursorCache.from = rebaseResult.from;
          cursorCache.to = rebaseResult.from;
          flag = false;
        } else {
          unconfirm = unconfirm.slice(messageArray[i].steps.length);
        }
        
      }
      unconfirm = unconfirm.map((v) => {
        return v.step;
      });

      steps = unconfirm;
    } else {
      steps = unconfirm.map((v: any) => {
        return v.step;
      })
    }
function rebaseStepsHandle(steps: any, over: Array<Step>, transform: any, from: number, to: number) {
  for (let i = steps.length - 1; i >= 0; i--) transform.step(steps[i].inverted);
  for (let i = 0; i < over.length; i++) {
    if (over[i]) {
      try {
        transform.step(over[i]);
      } catch (error) {
        console.log(transform.doc.nodeSize);
        throw error
      }
    }
  }
  let result = [];
  let newFrom;
  let newTo;
  for (let i = 0, mapFrom = steps.length; i < steps.length; i++) {
    let mapped = steps[i].step.map(transform.mapping.slice(mapFrom));
    mapFrom--;
    try {
      if (mapped && !transform.maybeStep(mapped).failed) {
        transform.mapping.setMirror(mapFrom, transform.steps.length - 1);
        result.push({ inverted: mapped.invert(transform.docs[transform.docs.length - 1]), step: mapped });
      }
    } catch (error) {
      //
    }
  }

I get this

RangeError: Position 2818 out of range

any suggest will be very helful :heart: :heart:

Hi. You didn’t really explain very well what you’re trying to do, and I definitely don’t have time to puzzle over random blobs of other people’s code, but if this is server-side code, it shouldn’t do anything with unconfirmed steps if there is a version mismatch, and just let the client handle rebasing those (preferably through the prosemirror-collab plugin).

my bad, Thanks for Reply