Skip to content

#9123 – Fix: Monomers disappearing when expanding/collapsing in Molecules Mode after moving in Macromolecules Mode#9503

Merged
AlexeyGirin merged 1 commit intomasterfrom
9123-monomer-structures-or-elements-disappear
Mar 31, 2026
Merged

#9123 – Fix: Monomers disappearing when expanding/collapsing in Molecules Mode after moving in Macromolecules Mode#9503
AlexeyGirin merged 1 commit intomasterfrom
9123-monomer-structures-or-elements-disappear

Conversation

@bekaChaduneli
Copy link
Copy Markdown
Collaborator

How the feature works? / How did you fix the issue?

Fixed a crash that caused monomer structures to disappear when trying to expand/collapse them in Molecules Mode after moving or selecting them in Macromolecules Mode.

Root cause:

Redux Toolkit uses Immer, which recursively freezes all objects placed into Redux state. When loadMonomerLibrary is dispatched, library items (and all their nested objects) become frozen. These frozen objects were then assigned directly to BaseMonomer.monomerItem via updateMonomerItem. When the user switched to Molecules Mode and tried to expand/collapse a monomer, writing to monomerItem.expanded threw:

Changes made:

  1. DrawingEntitiesManager.ts (updateMonomerItem) — Primary fix

    • Before: initialMonomer.monomerItem = monomerItemNew;
    • After: Checks Object.isFrozen(monomerItemNew) and creates a shallow copy if frozen before assigning
    • Prevents frozen Immer-managed library items from ever being stored directly on a monomer, fixing the root cause for all callers
  2. SGroupAttr.ts (execute) — Defensive fix at crash site

    • Before: Direct write sgroup.monomer.monomerItem.expanded = this.data.value
    • After: Checks if monomerItem is frozen and thaws it with a shallow copy before writing
    • Handles any monomers that already carry a frozen monomerItem in memory
  3. operations/sgroup/index.ts (SGroupAdd.execute) — Same defensive fix

    • Same pattern applied at the SGroupAdd path which also writes monomerItem.expanded

Check list

  • unit-tests written
  • e2e-tests written
  • documentation updated
  • PR name follows the pattern #1234 – issue name
  • branch name doesn't contain '#'
  • PR is linked with the issue
  • base branch (master or release/xx) is correct
  • task status changed to "Code review"
  • reviewers are notified about the pull request

@AlexeyGirin AlexeyGirin merged commit f12d5d2 into master Mar 31, 2026
15 checks passed
@AlexeyGirin AlexeyGirin deleted the 9123-monomer-structures-or-elements-disappear branch March 31, 2026 10:03
@github-project-automation github-project-automation bot moved this from In review to Done in EPAM contributors Mar 31, 2026
@AlexeyGirin AlexeyGirin removed this from the Ketcher 3.15.0-rc.1 (Current) milestone Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monomer structures or elements disappear when trying to expand/collapse monomers in Molecules Mode.

3 participants