Looking at the function rebaseSteps, it seems like there are situations when not all unconfirmed steps can be rebased, yet the rebased [1] number is based on the number of unconfirmed steps before trying to rebase steps on top of the incoming steps. So I believe it’s in these situations that tr.docs[tr.steps.length - rebased] comes up with the wrong result for me.
This seems to be working though:
let rebased = tr.getMeta("rebased")
let docNumber = rebased + stepsLength
let confirmedDoc = docNumber === tr.docs.length ?
tr.doc :
tr.docs[docNumber]
Where stepsLength is the number of steps as they were received from the server.
This is still a bit complex and new for me, so further tests may show problems with this also.