Custom blocks do not rerender on editor.isEditable change

Aperta
#2,134 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Start with the createReactBlockSpec custom block and the BlockNoteView editable toggle shown in the reproduction. Review fixes #2121 and #2106 to identify why the block does not react to editor.isEditable changes. Done means toggling the button changes the custom block content between "editable" and "readonly" without interacting with the block.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug:P2

Describe the bug
In version 0.41.1 custom blocks directly reacted to changes to editor.isEditable and have rerendered.
But at the latest main version they don't (until they are interacted with which forces a rerender).
I suspect this is due to the fix (#2121) for (#2106).

To Reproduce
block-spec:

export const createTestBlock = createReactBlockSpec(
    {
        type: 'test',
        propSchema: {
        },
        content: 'none',
    },
    {
        render: (props) => {
            return (
                <div>{props.editor.isEditable ? 'editable' : 'readonly'}</div>
            );
        },
    }
);

editor:

export function Test() {
    const [readonly, setReadonly] = useState(false);
    const editor = useCreateBlockNote({
        schema: BlockNoteSchema.create({
            blockSpecs: {
                test: createTestBlock(),
            },
        }),
        initialContent: [
            {
                type: "test",
            },
        ],
    });

    return <div>
        <button onClick={() => setReadonly(r => !r)}>toggle</button>
        <BlockNoteView editor={editor} editable={!readonly} />
    </div>;
}

Toggling the readonly button does not change block's content to readonly

Misc

  • Node version:
  • Package manager:
  • Browser:
  • I'm a sponsor and would appreciate if you could look into this sooner than later 💖
Lingua principale
TypeScript
Stelle
10.2k
Fork
772
Merge medio
3g 11h
PR unite (30g)
17

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TypeCellOS/BlockNote

Tutte le issue di TypeCellOS/BlockNote

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.