automerge / automerge-prosemirror

96 stars 5 forks source link

[cookbook] Prosemirror recipes are no longer reliable. #26

Open c4lliope opened 2 weeks ago

c4lliope commented 2 weeks ago

Hello - I'm going through the guide on: https://automerge.org/docs/cookbook/rich-text-prosemirror-react -- there are a few errors.

Primarily, the import from this package is no longer called AutoMirror; the docs should be changed to import { init } from ..., as in the README here. Secondly, I keep running into this error, although I can see no difference in the code I am using. Occasionally, one of Vite's hot module reloads on a page save kicks in, and I can finally reach an on-screen editor. Usually, such as in a manual refresh, I can only see the error.

https://github.com/automerge/automerge-prosemirror/blob/9f142a49786d15cd23f28783773893f9314c10fd/src/index.ts#L80 "cannot initialize ProseMirror document when handle is not ready"

c4lliope commented 2 weeks ago

Looking through the VanillaJS Prosemirror recipe also...

I repaired many of the same errors from the React guide; mainly changing the AutoMirror reference to init() again.

In addition to the handle readiness error, I am also running up on:

Uncaught TypeError: mirror.intercept is not a function
c4lliope commented 2 weeks ago

One more clue had been... erasing the document hash from the URL and refreshing, usually is enough to kick prosemirror into gear; coupled with the DocHandle error message, I'm researching the background I need on:

https://automerge.org/docs/repositories/dochandles/

The description of a DocHandle as a "Live Document"; one that can manage and respond to interactions and changes; is a good explanation of how ProseMirror relies so much on this binding, rather than the basic document model.

The URL quirk also implies that Repo.create({ page: '' }) is succeeding, whereas the Repo.find(....) or other similar secondary paths are missing the mark. Maybe the issue is in the Repo initialization somehow.

alexjg commented 2 weeks ago

Thanks for spotting this. I have a PR to update the docs here: https://github.com/automerge/automerge.github.io/pull/99