Skip to content

Automerge persister clears the document contents on startup #170

@wilkerlucio

Description

@wilkerlucio

Describe the bug

Hi, I'm doing a setup using Tinybase and automerge, and I notice I couldn't get the persistence from automerge to works.

I debug it, and I notice it was saving properly, but when I was reading it, the store always came back clean.

I traced it down to this first line in the createAutomergePersister code:

docHandle.change((doc: any) => (doc[docObjName] = {}));

So on start, it causes a new transaction that clears all the contents in the document.

I did a simple fix as (note the replacement of = with ||=):

docHandle.change((doc) => (doc[docObjName] ||= {}));

So this way I can start tinybase with an automerge doc that always has data.

Platform

  • OS: All
  • Browser: All
  • Version: 5.1.2

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