#9889 - Errors are displayed after switching between Expand and Colla…#10152
Open
PaulinaKacz wants to merge 3 commits into
Conversation
…pse and Macro and Micro modes.
added 2 commits
June 2, 2026 13:47
…pse and Macro and Micro modes. - error fix
…pse and Macro and Micro modes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
#1234 – issue name