Changing doc.attrs?

I’m relatively new to using prosemirror so I may be mistaken but I thought the document was supposed to be immutable. Wouldn’t this manipulate the current doc instance since it’s not creating a new doc?

@andrews - yes, the solutions in this thread modify the document in place. Whether that is a problem depends on what else you are doing in the transaction that uses this step (and how your application consumes transactions). We didn’t see any specific issues with this in the original situations we used this approach in, but have since switched to apply functions that produce a new document to support some additional use cases, e.g.:

apply(doc) { 
  const newDoc = Node.fromJSON(schema, doc.toJSON());

  newDoc.attrs.someData = produceNewSomeData(doc.attrs.someData);

  return StepResult.ok(newDoc);

Thanks. Yes that makes sense - would probably just need to alter the example to use the newDoc in the result. :slight_smile:

1 Like