MyScript / iinkTS

Other
52 stars 5 forks source link

Server state randomly corrupts and collapses the iink editor content #1

Closed pvnick closed 7 months ago

pvnick commented 10 months ago

I set up a editor to automatically convert strokes to text after a couple seconds of inactivity. Before long, the server seems to tell the client to collapse everything into a jumbled mess. "Undo" does not fix the situation - running the undo command will temporarily revert to the clean state on the client side, but the next time "convert" is run the content will get messed up again.

Minimal example to recreate the issue:


export class HandwritingEditor {
    private iinkEditor: IInkEditor
    private editorContainer: HTMLElement
    private editorElement: HTMLElement
    private resizeObserver: ResizeObserver
    private lastChangeID: string = ""

    constructor(applicationKey: string, hmacKey: string) {
        this.editorContainer = document.createElement('div')
        this.editorContainer.id = 'handwriting-editor-container'
        this.editorElement = document.createElement('div')
        this.editorElement.id = 'handwriting-editor'
        this.editorContainer.appendChild(this.editorElement)
        this.iinkEditor = new IInkEditor(this.editorElement,
            {
                configuration: {
                    server: {
                        scheme: "https",
                        host: "cloud.myscript.com",
                        applicationKey: applicationKey,
                        hmacKey: hmacKey,
                    },
                },
            }
        )
        setTimeout(() => {
            this.iinkEditor.initialize().then(() => {
                this.iinkEditor.events.addEventListener("changed", (evt: any) => {
                    const changeID = crypto.randomUUID()
                    this.lastChangeID = changeID
                    setTimeout(() => {
                        if (changeID == this.lastChangeID) {
                            this.iinkEditor.convert()
                        }
                    }, 2000)
                })
            })
        })
        this.resizeObserver = new ResizeObserver(this.refreshSize.bind(this));
        this.resizeObserver.observe(this.editorElement);
        this.refreshSize()
    }

    getEditorContainer() {
        return this.editorContainer
    }

    refreshSize() {
        this.iinkEditor.resize()
    }
}

let editor = HandwritingEditor("app key", "hmac key")
document.body.appendChild(editor.getEditorContainer())

Before collapse: pre-jumble

After collapse: after-jumble

pvnick commented 10 months ago

Btw I should also add that I think your service is really impressive and amazing, and I'm excited to continue using it.

srobert-myscript commented 9 months ago

Hello pvnick, thank you for your support. This bug was already identified and our team solved it. It should be present in the next release.

For your information it is due to a force convert at reconnect.

We add a new Configuration parameter:

convert: {
      force: {
        'on-stylesheet-change': false
      }
},
pvnick commented 9 months ago

Cool! Thank you!

leJsboureau commented 7 months ago

New version (1.0.4) with fix configuration available. Thank you for your feedback.