Skip to content

fix(portal): guard removeChild against externally cleared mount#2794

Open
tsushanth wants to merge 1 commit into
solidjs:mainfrom
tsushanth:fix/portal-cleanup-guard
Open

fix(portal): guard removeChild against externally cleared mount#2794
tsushanth wants to merge 1 commit into
solidjs:mainfrom
tsushanth:fix/portal-cleanup-guard

Conversation

@tsushanth

Copy link
Copy Markdown

Fixes #2775

Disposing a Portal throws NotFoundError if the mount node is externally cleared before Solid's cleanup callbacks run. el.removeChild(container) fails because container is no longer a child of el.

The fix guards the call with el.contains(container) so cleanup is a no-op when the container has already been detached. Regression test added to portal.spec.tsx.

If the portal mount node is cleared externally (e.g. via innerHTML = "")
before Solid's cleanup runs, the onCleanup callback would throw a
NotFoundError because the container is no longer a child of el.

Guard the removeChild call with el.contains(container) so disposal is a
no-op when the container has already been removed from the DOM.

Fixes solidjs#2775
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d91dd89

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Portal cleanup throws if mount was externally cleared (1.x and 2.0.0-beta-14)

1 participant