Repository navigation
Remove a Portal element from its own parent - #134
Open
spot-uncountable wants to merge 1 commit into
Open
spot-uncountable wants to merge 1 commit into
spot-uncountable wants to merge 1 commit into
Conversation
Portal removed its element from document.querySelector('.Ketcher-root').
The platform embeds more than one editor on a page, so that selector can
resolve to another instance's root, and removeChild then throws
NotFoundError: The node to be removed is not a child of this node.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Description
Portalremoved its element fromdocument.querySelector('.Ketcher-root')instead of from the node that actually holds it. The platform embeds more than one editor on a page, so that selector can resolve to another instance's root, andremoveChildthen throwsNotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.The same lookup also makes the removal a silent no-op whenever no
.Ketcher-rootis in the document, which leaks the element.MicromoleculesEditordetaches its root before its inner React root unmounts, so that is the normal single-editor path.Reported from production as Sentry UNC-F-9BT (uncountableinc/main MAT-88700). React 19 surfaces the throw to
window.onerror, so it now reaches error reporting.Reproduction
In the Uncountable platform, with the fork build currently pinned (
3.6.0-unc53):Portal..Ketcher-rootin the document ahead of the editor's own root, which is what a second embedded editor does.Both steps 3 throw, with this stack:
With
this.element.remove()patched into the served bundle, the same two flows raise no error and the element is detached from its real parent.Testing
ketcher-autotests/tests/specs/unc-regression/editor-instance.spec.tsgains a case that opens the area-selection dropdown, inserts a second editor root, then selects a tool to close the dropdown, and asserts no page error. The case fails on the current code and passes with this change.Note: the pre-commit and pre-push hooks could not run in the agent pod.
npm cicompleted, butlint-stagedandrun-sare absent and a furthernpm installwas OOM-killed.npx prettier --checkon both changed files passes; the rest of the checks are left to CI.