Skip to content

$inspect() of shared external state fires unexpectedly in conditionally nested component #14891

@mjadobson

Description

@mjadobson

Describe the bug

This was an unexpected behaviour I noticed:

Given an external state, where a parent component conditionally renders a child component based on it. If the child component references it in an $inspect(), the $inspect() will fire even though the component should have been destroyed.

This can lead to errors where you expect the external state to be a certain shape in the child component.

This doesn't happen with render or user effects.

Reproduction

https://svelte.dev/playground/d5df84a246d742308383c661d658bf81?version=5.16.1

Click Init Items, then Reset Items to show the behaviour.

Logs

No response

System Info

System:
  OS: macOS 15.0.1
  CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
  Memory: 715.43 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.12.1 - /usr/local/bin/node
  npm: 10.5.0 - /usr/local/bin/npm
Browsers:
  Chrome: 131.0.6778.205
  Safari: 18.0.1
npmPackages:
  svelte: ^5.16.1 => 5.16.1

Severity

annoyance

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