-
-
Notifications
You must be signed in to change notification settings - Fork 550
fix: insertblocks when no type is provided #1436
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -281,7 +281,10 @@ export function blockToNode( | |||
|
|||
const nodeTypeCorrespondingToBlock = schema.nodes[block.type]; | |||
|
|||
if (nodeTypeCorrespondingToBlock.isInGroup("blockContent")) { | |||
if ( | |||
!nodeTypeCorrespondingToBlock || // can happen if block.type is not (this should create the default node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a little clearer. Maybe something more like:
const nodeTypesCorrespondingToBlock = schema.nodes[block.type ?? 'blockContent']
Or, whatever makes sense as the default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see update, the issue is that schema.nodes[undefined] is valid javascript but ofc. returns undefined. TS would say the returntype would be NodeType
which is invalid.
To fix this we'd need to make the index signature of nodes
return NodeType | undefined
with a PR to pm-model. I think that's a bit overkill here so I now typed nodeTypeCorrespondingToBlock
explicitly. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, agreed that isn't necessary. But, I was more referring to that since block.type could be undefined, it should not be used to index the schema.nodes object, and should instead use whatever fallback would be there (so you don't even need the !nodeTypeCorrespondingToBlock || [XX]
part.
Not a big deal though, the explicit type helps make it clearer a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I think it's better now
This addresses a regression after multi-column where
insertBlocks
(andblockToNode
) would throw an error if no block type was provided in the partialblock. Also added unit testcloses #1408