Bug: can't limit nodes/commands that nested editors accept
See original GitHub issueCurrently it doesn’t seem possible to restrict the kind of content that can be placed inside nested editors.
I can work around this by disabling toolbar buttons based on whether the active editor includes a command in it’s _commands
set: !activeEditor._commands.has(MY_CUSTOM_COMMAND)
but that doesn’t seem ideal.
Lexical version: 0.3.11 but also verified against Playground from main (e.g. https://lexical-playground-git-041-fbopensource.vercel.app/)
Steps To Reproduce
- Open the Playground
- Insert a Sticky or a Image with a Caption
- Within the nested editor, insert an Image, bold some text etc…
The current behavior
Currently, following the above steps will result in bold text or an image inside in the Sticky, despite the StickyPlugin being configured to accept PlainText:
<LexicalNestedComposer
initialEditor={caption}
initialTheme={StickyEditorTheme}>
{isCollabActive ? (
<CollaborationPlugin
id={caption.getKey()}
providerFactory={createWebsocketProvider}
shouldBootstrap={true}
/>
) : (
<HistoryPlugin externalHistoryState={historyState} />
)}
<PlainTextPlugin
contentEditable={
<ContentEditable className="StickyNode__contentEditable" />
}
placeholder={
<Placeholder className="StickyNode__placeholder">
What's up?
</Placeholder>
}
// TODO Remove after it's inherited from the parent (LexicalComposer)
initialEditorState={null}
/>
</LexicalNestedComposer>
A similar thing happens with commands. When a command is defined by a plugin that isn’t registered on the nested editor, the triggerCommandListeners function iterates the active editors, recognises that there’s no listener registered for the command on the nested editor, but then sends the command to the parent editor which just inserts the node within the nested editor anyway.
The expected behavior
I’d expect:
- Nested editors to only accept Nodes that are configured on the Nested editor
- Commands issued to a nested editor that isn’t configured to accept them should not result in the command executing and inserting nodes into the nested editor.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
This was actually fixes last night https://github.com/facebook/lexical/pull/2947!
Ok that makes sense.
When
__DEV__
is true the above behaviour occurs, when__DEV__
is false a slightly different error occurs:Is that expected behaviour?