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

🐛 Fixes a bug where 'handleNodeClick' could runtime error if the node had already been removed. #3294

Merged
merged 3 commits into from
Aug 9, 2023

Conversation

hayleigh-dot-dev
Copy link
Contributor

Two changes:

  • handleNodeClick no-ops if the target node doesn't exist.
  • A new error is reported:
`Node with id "${id}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called. If this wasn't on purpose, please defer deleting this node until the "onNodeClick" handler is called by using "requestAnimationFrame" or "setTimeout".`

This can come up if a custom node has a delete button, for example, and the user also has a onNodeClick handler set up on the <ReactFlow> component.

@hayleigh-dot-dev
Copy link
Contributor Author

See xyflow/react-flow-docs#131 for the companion docs update.

@@ -17,4 +17,6 @@ export const errorMessages = {
}", edge id: ${edge.id}.`,
error010: () => 'Handle: No node id found. Make sure to only use a Handle inside a custom Node.',
error011: (edgeType: string) => `Edge type "${edgeType}" not found. Using fallback type "default".`,
error012: (id: string) =>
`Node with id "${id}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called. If this wasn't on purpose, please defer deleting this node until the "onNodeClick" handler is called by using "requestAnimationFrame" or "setTimeout".`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Node with id "${id}" does not exist, it may have been removed." - this is enough for the error message

@moklick moklick changed the base branch from main to next-release August 9, 2023 08:55
@moklick moklick merged commit 994878d into next-release Aug 9, 2023
@moklick moklick deleted the fix/deleted-node-click-handler branch August 9, 2023 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants