Skip to content

Bug: Uploading content to new Document with createDocWithContent creates empty document #426

Description

@MaSp005

Hi, I am attempting to offer users to upload a locally created document to a shared document:

const yDoc = new Y.Doc();
const yMap = yDoc.getMap('crazyWall');
const unbind = bind<any>(WallProxy /* valtio proxy storing the JSON document */, yMap);
// I did test this, binding late does populate the empty storage with content from the other,
// printing the below buffer shows that it changes with differing input.

const state = Y.encodeStateAsUpdateV2(yDoc);
const buffer = Buffer.from(state);

return (await fetch("/api/newdoc", {
  method: "POST",
  body: buffer
}).then(r => r.json())).docId;

(See https://github.com/MaSp005/crazywall/blob/f10831b51944dd1dfed6c4c7f96e99f3fe0c6f1a/src/contexts/globalContext.ts#L276-L291)

The server will then create the document with the uploaded content:

const body = await request.arrayBuffer();
const content = new Uint8Array(body);
// This stores the same bytes as the buffer on the client.
const { docId } = await yManager.createDocWithContent(content);

(See https://github.com/MaSp005/crazywall/blob/f10831b51944dd1dfed6c4c7f96e99f3fe0c6f1a/src/index.ts#L70-L94)


Expected behaviour: Viewing the created document shows the exact state as uploaded before.

Observed behaviour: Visiting the created document afterwards shows an entirely empty document.

I attempted to step through the y-sweet server, and the update from the backend does reach DocWithSyncKv#apply_update, but I couldn't trace it further.

Is this an issue with my usage of the library or a bug with the server? Thanks!

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