beforeAdd event is not working on diagram

Hello,
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:
https://snippet.dhtmlx.com/m4gz4y7m
If the problem still occurs for you please, provide a code snippet or a complete demo, where the problem can be reconstructed.