Skip to content

Manually mounted component fails to update after DOM reinsertion #16695

@SkylerLipthay

Description

@SkylerLipthay

Describe the bug

Component rendering breaks after manually inserting a mounted component into one DOM node and then moving it into another.

I'm not sure if this sort of thing was ever officially supported. I haven't found anything in the docs. This pattern worked in 5.22.2 but broke in 5.22.3 (5 months ago) due to effect processing changes.

My exact use case is a complex "tiling window manager" component akin to GoldenLayout. The basic requirement is to preserve the exact DOM state of a component instance when it's conditionally rendered in different locations. The component contains complex internal state (form inputs, scroll position, third-party widget state, etc.) that can't be serialized/restored. I need the exact same component instance DOM to be reused rather than destroyed/recreated.

I've written a minimal reproduction below. Pressing the inc button works as expected until the swap button is pressed, then the inc button stops working.

If this is an unsupported technique, any advice would be appreciated.

Reproduction

System Info

Binaries:
  Node: 24.6.0
  npm: 11.5.1
Browsers:
  Chromium: 138.0.7204.183
npmPackages:
  svelte: 5.38.6 => 5.38.6

Severity

blocking an upgrade, regression

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions