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

After dnd of a custom block, the editor sometimes loses the block or changes its data unexpectedly. #1396

Open
ellykiddy opened this issue Jan 28, 2025 · 7 comments
Labels
bug Something isn't working

Comments

@ellykiddy
Copy link

Describe the bug
Sometimes, the editor loses a block after dnd. I added logs to the onEditorContentChange function, and after dnd, the block is missing from the editor document. It seems like the block just disappears.

To Reproduce
https://drive.google.com/file/d/1zVuWurChspTwsIGIiwXM3iNOt1Hb0gN8/view?usp=sharing

Misc
Node version: v16.14.2
Package manager: pnpm
Browser: Chrome 132

@ellykiddy ellykiddy added the bug Something isn't working label Jan 28, 2025
@YousefED
Copy link
Collaborator

Thanks for reporting. @ellykiddy which version of blocknote are you using?

@ellykiddy
Copy link
Author

ellykiddy commented Jan 28, 2025

0.23.0
now I saw that 0.23.1 has been released

ps: checked changelog; the issue must be on 0.23.1 too

@YousefED
Copy link
Collaborator

Thanks. Does anything appear in the browser logs, or can you reproduce it with an isolated example (e.g.: on stackblitz)?

@homecheck-garden
Copy link

homecheck-garden commented Feb 1, 2025

I am encountering the same exception. In the browser console, it appears like this.
And I am using multiple editors on a single page, controlling them with the editable property.

"@blocknote/core": "^0.23.1",
"@blocknote/mantine": "^0.23.1",
"@blocknote/react": "^0.23.1",
"next": "^15.2.0-canary.6",
"react": "^19.0.0",
"react-dom": "^19.0.0",

Exception Message in browser console is
Cannot update a component (to) while rendering a different component ('BlockSuiteViewWrapper'). To locate the bad setState() call inside 'BlockSuiteViewWrapper', follow the stack trace as described in https://react.dev/link/setstate-in-render

BlockSuiteViewWrapper is BlocksuiteWrapper

BlockSuiteWrapper.tsx

'use client'
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {   
  DragHandleButton,
  SideMenu,
  SideMenuController,
  useCreateBlockNote, 
  BlockColorsItem,
  DragHandleMenu,
  SuggestionMenuController,
} from "@blocknote/react";
import { filterSuggestionItems } from '@blocknote/core'
import { createPortal } from 'react-dom';
import { getSlashMenuComponent, getSlashMenuItems } from './slashMenu'
import { stringDictionary } from './locales'




export default function BlockSuiteWrapper({editable } : {
  editable : boolean
}){
  const editor = useCreateBlockNote({
    dictionary : stringDictionary,
    animations : false,
    sideMenuDetection : editable ? 'editor' : 'viewport'
  });




  editor.isEditable = editable;
  return (
    <div>
      <BlockNoteView 
      editor={editor} 
      sideMenu={false} 
      onChange={()=>
        console.log(
          editor.document)
      }
      slashMenu={false}
      theme={"light"}>
        <SideMenuController
          sideMenu={(props) => (
            <SideMenu {...props} >
                <DragHandleButton {...props}
                dragHandleMenu={(props) => (
                    <DragHandleMenu {...props}>
                      <BlockColorsItem {...props}>색상</BlockColorsItem>
                    </DragHandleMenu>
                  )}>
                </DragHandleButton>
              </SideMenu>
          )}
        />
        {createPortal(
          <SuggestionMenuController
            triggerCharacter={"/"}
            suggestionMenuComponent={getSlashMenuComponent}
            floatingOptions={{
              strategy : "fixed",
              placement : "bottom",
            }}
            getItems={async (query) =>
              filterSuggestionItems(getSlashMenuItems(editor), query)
            }
            ></SuggestionMenuController>
        , document.body!)}
      </BlockNoteView>
      </div>
  );
}

@YousefED
Copy link
Collaborator

YousefED commented Feb 1, 2025

Thanks @homecheck-garden . Would it be possible to create a reproducible example, for example using Stackblitz?

@homecheck-garden
Copy link

@YousefED sure. can you see this url?

StackblitzURL

@homecheck-garden
Copy link

homecheck-garden commented Feb 7, 2025

I'm sorry if I sound like I'm rushing you, but could you please let me know if there are any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants