epam / ketcher

Web-based molecule sketcher
https://lifescience.opensource.epam.com/ketcher/demo.html
Apache License 2.0
498 stars 172 forks source link

Exception when modifying a functional group after adding a ketcher editor subscription #5988

Open askyel opened 4 days ago

askyel commented 4 days ago

Steps to Reproduce

  1. Go to https://lifescience.opensource.epam.com/KetcherDemoSA/index.html or use ketcher v.2.25.0
  2. Execute ketcher.editor.subscribe("change", () => console.log("hello")); in the console (or add any other change subscription)
  3. In the canvas, add a functional group such as "CF3"
  4. Click on another atom such as "Br" and click on the functional group
  5. Exceptions are thrown and the canvas becomes blank

Actual behavior After a ketcher editor subscription is added for a "change" event, trying to replace a functional group, expand a functional group, or contract a functional group causes exceptions to be thrown. In addition, the ketcher canvas becomes blank. This is the stracktrace shown for the exception:

Uncaught TypeError: Cannot read properties of undefined (reading 'type')
    at eval (index.modern.js:17491:16)
    at Array.forEach (<anonymous>)
    at customOnChangeHandler (index.modern.js:17489:31)
    at subscribeFuncWrapper (index.modern.js:24527:22)
    at Subscription.dispatch (index.js:51:19)
    at Editor.update (index.modern.js:24463:29)
    at AtomTool.mouseup (index.modern.js:16678:14)
    at useToolIfNeeded (index.modern.js:24661:130)
    at Handler.eval [as f] (index.modern.js:24721:24)
    at DOMSubscription.dispatch (index.js:93:21)
    at HTMLDocument.eval (index.modern.js:24708:21)
    at HTMLDocument.sentryWrapped (helpers.js:106:17)

Expected behavior The correct functional group modification on the canvas structure - in this case the "Br" atom replacing the "CF3" functional group.

Screenshots https://github.com/user-attachments/assets/ebccc96a-eb12-4d08-88c0-c0402fb0552c

image

Desktop (please complete the following information):

Ketcher version v2.25.0

rrodionov91 commented 3 days ago

Hi @askyel Thank you for highlighting this issue. We will check it out.