beforeAdd event is not working on diagram

I am trying to use beforeAdd event for diagram.
According to documentation (beforeAdd Event of Data Collection | DHTMLX JavaScript Diagram Docs) if i return true it will add item in data collection and on returning false it will not add item in data collection.
when i return false it gives error Uncaught TypeError: Cannot read properties of undefined (reading ‘$item’) on diagramWithEditor.js

Version used: 5.0.0

Anyone else faced this issue ?

I apologize for the delay with the reply.
Unfortunately I was not able to reproduce your issue locally.
The following snippet works well for me locally:
If the problem still occurs for you please, provide a code snippet or a complete demo, where the problem can be reconstructed.

i’m sorry, but your snipet don’t work fine if collback return false

In this case, the new element is displayed on the diagram. (But it is impossible to interact with him). An error appears in the browser console.
If you try to add an element again, the one that is frozen will disappear from the form.
Please tell me how to make sure that the element is not added to the diagram.

I apologize for the misunderstanding.

Your problem was confirmed. And will try to fix it in one of the future updates.
I’ll inform you here about any progress on this issue.
Thank you for your report.