Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do you really have to create the root upfront? #388

Open
SebastianStehle opened this issue Feb 12, 2024 · 2 comments
Open

Do you really have to create the root upfront? #388

SebastianStehle opened this issue Feb 12, 2024 · 2 comments

Comments

@SebastianStehle
Copy link

Hi,

I got a bug report for our .NET wrapper. The code example is as followed:


        var localDoc = new Doc();
        var localText = localDoc.Text("name");

        using (var tx = localDoc.WriteTransaction())
        {
            localText.Insert(tx, 0, "Y-CRDT");
            tx.Commit();
        }

        var remoteDoc = new Doc();

        byte[] remoteState;
        // Get the remote document state vector.
        using (var tx = remoteDoc.ReadTransaction())
        {
            remoteState = tx.StateVectorV1();
            tx.Commit();
        }

        byte[] stateDiff;
        using (var tx = localDoc.ReadTransaction())
        {
            stateDiff = tx.StateVectorV1();
            tx.Commit();
        }

        using (var tx = localDoc.WriteTransaction())
        {
            tx.ApplyV1(stateDiff);
            tx.Commit();
        }

        using (var tx = remoteDoc.ReadTransaction())
        {
            Text? textProperty = tx.GetText("name");
            // as a new user, I expected this to return the Text since the sync should have created
            // it.

            // Instead, the docs state it should be null: "Returns the Text at the Doc root level, identified by name, 
            // or null if no entry was defined under name before." However, it throws instead.
            Assert.NotNull(textProperty);
        }

The user asked if it is by design that the does not see the root, if he uses the code above. I was also not sure about this and whether he or I made something wrong. Could also be a bug ofc.

@Horusiath
Copy link
Collaborator

Yes, applying updates should create (temporarily) untyped roots if they were not defined before. We have tests that confirm that behaviour in yrs and (I think) in ywasm. I'll check it out for C bindings, but the code is very straightforward.

@SebastianStehle
Copy link
Author

Sorry, I forgot to mention that the code above fails. It returns null. So I have to create the root first, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants