FluidFramework icon indicating copy to clipboard operation
FluidFramework copied to clipboard

Getting `null` property value when iterating segments in SharedString.

Open ZeguangWu opened this issue 6 years ago • 5 comments

Describe the bug

FF runtimes doesn't have sanitized nulls on insert, and null mean delete a property. So when there is an insert op with null property values, it will end up being in the SharedString, so when a client iterates the segments it will get null property value.

@anthony-murphy :This makes sense. We don't currently and never have sanitized nulls on insert, and null mean delete a property, but we can pretty easily add sanitization there. Currently think we will sanitize before we send the ops so not all clients need to pay the cost.

Given there are some Scriptor documents already have null properties in their summary, it'd be nice to clean up those null properties in the runtime. For short term, Scriptor can ignore those null properties when walking segements.

ZeguangWu avatar Aug 27 '20 20:08 ZeguangWu

@ZeguangWu - I set up a few tests to check on those null values, but I can't seem to repro it in Mocha. These are the two tests I have so far, and both pass:

it("can handle null annotations in the text", async () => {
            const text = "hello world";
            // eslint-disable-next-line no-null/no-null
            const startingProps = { style: "bold", color: null };
            sharedString.insertText(0, text, startingProps);

            for (let i = 0; i < text.length; i++) {
                assert.strictEqual(
                    sharedString.getPropertiesAtPosition(i).color, undefined, "Null values allowed in properties");
            }

            // eslint-disable-next-line no-null/no-null
            const updatedProps = { style: null };
            sharedString.annotateRange(6, text.length, updatedProps);

            for (let i = 6; i < text.length; i++) {
                assert.strictEqual(
                    sharedString.getPropertiesAtPosition(i).style,
                    undefined,
                    "Null values allowed in properties");
            }
        });

I'm getting this when I run it

image

micahgodbolt avatar Sep 01 '20 23:09 micahgodbolt

seems the color key is properly set to undefined in my tests

micahgodbolt avatar Sep 01 '20 23:09 micahgodbolt

It seems we're already sanitizing for null values here:

https://github.com/microsoft/FluidFramework/blob/abc64a88a2c29e7646387a1da55de2a91142baf1/packages/dds/merge-tree/src/segmentPropertiesManager.ts#L101-L107

micahgodbolt avatar Sep 01 '20 23:09 micahgodbolt

Maybe it's in a differnt code path? Let me try if I can get a repro and will report back:)

ZeguangWu avatar Sep 02 '20 16:09 ZeguangWu

@micahgodbolt I think I know why. The problem happened in one of our old schema document, which for all markers, we stores all Scriptor properties as one property on the marker segment. And the null value is actually part of that "properties" object.

Feel free to close this issue.

ZeguangWu avatar Sep 02 '20 17:09 ZeguangWu