Skip to content

Adding <hr> breaks loading from automerge #25

Open
@kythyria

Description

Attempting to modify the schema in src/schema.ts to add support for <hr> looks initially like it will work, but instead attempting to load a document with one in causes automerge-prosemirror to crash during initialization:

Uncaught Error: Match cannot be null
    set currentMatch traversal.ts:619
    newBlock         traversal.ts:650
    traverseSpans    traversal.ts:597
    pmDocFromSpans   traversal.ts:64
    init             index.ts:84
    <anonymous>      main.ts:40

It crashes in a similar way--the top four frames are identical--while-you-edit if two copies of the page are open pointing at the same document.

The actual substantial change to repro is to copy src/schema.ts and modify the bit about horizontal rules to read

    /// A horizontal rule (`<hr>`).
    horizontal_rule: {
      automerge: {
          block: "__ext__horizontal-rule",
          isEmbed: true,
      },
      group: "block",
      parseDOM: [{ tag: "hr" }],
      toDOM() {
        return hrDOM
      },
    } as NodeSpec,

then pass the resulting schemaAdapter to init().

https://github.com/kythyria/automerge-prosemirror-issue-badblocks is a vanilla JS example sufficient to reproduce, npm run dev, open the URL, try inserting a <hr> using the toolbar (could probably paste one too), observe that reloading the page fails, as does opening it in a second tab.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions