Skip to content

#9889 - Errors are displayed after switching between Expand and Colla…#10152

Open
PaulinaKacz wants to merge 3 commits into
masterfrom
9889-errors-are-displayed-after-switching-between-expand-and-collapse-and-macro-and-micro-modes
Open

#9889 - Errors are displayed after switching between Expand and Colla…#10152
PaulinaKacz wants to merge 3 commits into
masterfrom
9889-errors-are-displayed-after-switching-between-expand-and-collapse-and-macro-and-micro-modes

Conversation

@PaulinaKacz
Copy link
Copy Markdown
Collaborator

This PR fixes a regression where structure errors could appear after collapsing/expanding monomer functional groups, switching between Macro and Micro modes, and then using Snake mode.

Problem
In specific workflows (especially multi-selection collapse/expand and Snake layout transitions), attachment-point/bond mapping could become inconsistent, which later produced structure validation errors.

Root Cause
1 Multi-selection expand/collapse was using monomer-specific logic that is safe for simple monomer topologies but fragile for complex/multi-group operations.
2 For monomers with more than 2 attachment points, monomer-specific expand/collapse logic could destabilize state after mode switches.
3 During Macro -> Micro conversion, attachment-point mappings could be missing/stale for some polymer and monomer-to-atom bonds.

Changes
1 Switched multi-selection context-menu handling to generic S-group expansion/collapse:
useMonomerExpansionHandlers.ts
useFunctionalGroupEoc.ts
2 Added fallback in monomer expand/collapse:
For monomers with >2 attachment points, use generic S-group logic instead of monomer-specific logic.
sgroup.ts
3 Hardened attachment-point synchronization before conversion:
Added synchronization for polymer bonds and monomer-to-atom bonds before converting drawing entities to Struct.
MacromoleculesConverter.ts
4 Fixed type/runtime consistency in converter import (required for instanceof checks):
MacromoleculesConverter.ts

Why this is safe
1 The behavioral change is targeted to risky paths:
multi-selection operations and high-attachment-point monomers.
2 Existing logic for single simple monomer expand/collapse remains unchanged.
3 Converter changes are defensive and only restore missing mappings when absent.
Tests Added
1 React regression test for multi-selection path:
Ensures multi-selection uses generic S-group expansion/collapse.
useFunctionalGroupEoc.test.ts
2 Core regression test for >2 attachment points:
Ensures fallback to generic S-group logic is applied.
sgroup.test.ts

Validation Performed
1 Unit tests:
useFunctionalGroupEoc.test.ts
sgroup.test.ts
2 Type checks:
packages/ketcher-core and packages/ketcher-react passed tsc --noEmit.
3 Manual verification:
Original user scenario reproduces correctly without structure errors.

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

Paulina_Kwapisz added 2 commits June 2, 2026 13:47
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.

1 participant