TypeCellOS / BlockNote

A React Rich Text Editor that's block-based (Notion style) and extensible. Built on top of Prosemirror and Tiptap.
https://www.blocknotejs.org/
Mozilla Public License 2.0
6.2k stars 420 forks source link

Manipulate block after connecting with collaboration service #632

Closed zrg-team closed 5 months ago

zrg-team commented 5 months ago

Describe the bug

I can not manipulate block structure after connecting with collaboration services

To Reproduce

connect to collaboration provider

const editor = useBlockNote(
    {
      defaultStyles: false,
      slashMenuItems: specificationPageMenuItems,
      collaboration: {
        // The Yjs Provider responsible for transporting updates:
        provider,
        // Where to store BlockNote data in the Y.Doc:
        fragment: getXmlFragment(),
        // Information (name and color) for this user:
        user
      }
    }, []
  )

After replace with Db blocks

useEffect(() => {
   if (editor && !isReady && (currentBlockPageContentForSpecification?.length > 0 || blockPageForSpecification?.[blockPageId]?.children?.length === 0)) {
      console.log('look like it ready')
      setTimeout(() => {
        const deleteIds = editor.topLevelBlocks.map((block) => block.id)
        editor.removeBlocks(deleteIds)
        editor.replaceBlocks(
           editor.topLevelBlocks.,
           [...currentBlockPageContentForSpecification],
           true
        )
        console.log('manually update to socket')
        setIsReady(true)
      }, 2000)
    }
  }, [isReady, editor, currentBlockPageContentForSpecification, blockPageForSpecification?.[blockPageId]])

Misc

zrg-team commented 5 months ago

I found that if only block ['initialBlockId'] then all maninuplate block will not wor

YousefED commented 5 months ago

Hi @zrg-team, could you try upgrading to 0.12? If the issue still occurs, I'll reopen the issue. it's easiest for us to fix it if you can provide a codesandbox / stackblitz as well