sideboard: stop projections sharing the automerge doc object - #78
paulsonnentag wants to merge 3 commits into
Conversation
A document created in a folder showed up three times in the sidebar until reload (#58). The folder doc itself was fine; the Solid store behind the list had three entries. solid-automerge's makeDocumentProjection does createStore(handle.doc()), so the automerge document's own materialized object becomes the store's raw object and every patch is written into it in place. handle.doc() returns the same object for every handle of a document, and when a folder is open in the main pane several <patchwork-view>s each hold their own overlay handle for it (sidebar, the folder's own document list, the title bar). Each projection applied the same insert patch to the one shared array, so the row appeared once per projection. solid-automerge 2.0.1 is already the latest, so bumping it doesn't help. Replace useDocument/makeDocumentProjection in the sideboard with a local version whose store starts from, and is only ever reconciled against, a structuredClone of the doc. It's still built on solid-automerge's useDocHandle and autoproduce; only the ownership of the store's raw object changes. Adds a unit test that fails against the upstream implementation.
🪡 Patchwork previewTorn down. |
tldraw failed to load on fresh builds of the tools bundle: Failed to resolve module specifier "@automerge/automerge-repo-network-broadcastchannel" Both tools took useDocument/useRepo/RepoContext and DocHandle/Repo types from @automerge/react, which also re-exports every network adapter. The bootloader pinned in their lockfiles (0.7.2) lists the broadcastchannel adapter as an external, so esbuild left the re-export as a bare import; but the deployed shell's import map is generated from an older bootloader and has no entry for it, so the browser throws at import time. Take the hooks from @automerge/automerge-repo-react-hooks (already a dependency) and the types from @automerge/automerge-repo/slim, and drop @automerge/react. The built tool.js no longer references the adapter at all, so it loads regardless of which bootloader the shell was built with.
let me just do this upstream instead |
A document created in a folder showed up three times in the sidebar until reload (#58). The folder doc itself was fine; the Solid store behind the list had three entries.
solid-automerge's makeDocumentProjection does createStore(handle.doc()), so the automerge document's own materialized object becomes the store's raw object and every patch is written into it in place. handle.doc() returns the same object for every handle of a document, and when a folder is open in the main pane several s each hold their own overlay handle for it (sidebar, the folder's own document list, the title bar). Each projection applied the same insert patch to the one shared array, so the row appeared once per projection. solid-automerge 2.0.1 is already the latest, so bumping it doesn't help.
Replace useDocument/makeDocumentProjection in the sideboard with a local version whose store starts from, and is only ever reconciled against, a structuredClone of the doc. It's still built on solid-automerge's useDocHandle and autoproduce; only the ownership of the store's raw object changes. Adds a unit test that fails against the upstream implementation.