ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
27.64k stars 2.3k forks source link

[Bug]: When i use Y.createDocFromSnapshot,then use TiptapTransformer.fromYdoc happen error #5048

Open ZhangMingZhao1 opened 7 months ago

ZhangMingZhao1 commented 7 months ago

Which packages did you experience the bug in?

@hocuspocus/transformer

What Tiptap version are you using?

"@hocuspocus/transformer": "^2.11.3",       "@tiptap/core": "^2.2.4",

What’s the bug you are facing?

This case happened when I used a combination of tiptap and yjs. I wanted to create a multi-version history and then convert the version record into tiptap data.

when i click createVersion, view will add a div,but i click this div, only the first will'not report error,when I create multiple historical div tags, I will get an error whenever I click on one that is not the first one.

I find it that tiptap transformer actually use the y-prosemirror’s’yDocToProsemirrorJSON’ fucntion , happen error when converting to delta shema.

vue3 template

<template>
    <div>person: <el-avatar v-for="user in users" :key="user.name"> {{ user.name }} </el-avatar>
    <button class="create-btn" @click="createVersion">createVersion</button>
    <button class="version-time" v-for="(version, index) in versionsRef" :key="index" @click="reverseThisVersion(version)">
        {{new Date(version.date).toLocaleString()}}
    </button>
    </div>
    <editor-content :editor="editor" />
    <content-item-menu v-if="editor" :editor="editor"></content-item-menu>
    <text-menu v-if="editor" :editor="editor"></text-menu>
</template>

js:

const createVersion = () => {
    const versions = ydoc.getArray('versions')
    const snapshot = Y.snapshot(ydoc)
    versions.push([{
        date: new Date().getTime(),
        // snapshot: Y.encodeSnapshot(snapshot),
        snapshot,
        clientID: ydoc.clientID
    }])
    versionsRef.value = versions.toArray() as Array<object>
}
const reverseThisVersion = (version)=>{
    const { snapshot } = version;
    console.log('snapshot',snapshot)
    const result = Y.createDocFromSnapshot(ydoc, snapshot);
    console.log('result', result)
    const node = TiptapTransformer.fromYdoc(result);
   // happen error
    console.log('node', node)
}

error message :

Uncaught TypeError: item.toDelta is not a function
    at serialize (chunk-3S5FCWXE.js?v=80aede96:1148:26)
    at Array.map (<anonymous>)
    at yXmlFragmentToProsemirrorJSON (chunk-3S5FCWXE.js?v=80aede96:1185:20)
    at yDocToProsemirrorJSON (chunk-3S5FCWXE.js?v=80aede96:1140:10)
    at @hocuspocus_transformer.js?t=1712665928636&v=80aede96:2434:21
    at Array.forEach (<anonymous>)
    at Prosemirror.fromYdoc (@hocuspocus_transformer.js?t=1712665928636&v=80aede96:2433:15)
    at Tiptap.fromYdoc (@hocuspocus_transformer.js?t=1712665928636&v=80aede96:2465:35)
    at Proxy.reverseThisVersion ([fileId].vue:69:36)
    at onClick ([fileId].vue:4:95)

111

What browser are you using?

Chrome

Code example

still not yet

What did you expect to happen?

console this version tiptap content data

Anything to add? (optional)

111

Did you update your dependencies?

Are you sponsoring us?

ZhangMingZhao1 commented 5 months ago

@ZhangMingZhao1 were you able to fix this?

fixed already, my mistake

AitBaali-Hamza-bcg commented 4 months ago

@ZhangMingZhao1 what was the fix, I'm facing the same issue here

matheusAle commented 2 months ago

@ZhangMingZhao1 @AitBaali-Hamza-bcg same issue here... I notice that it could be related to custom extensions. have you guys found a solution?