Incorrect prop value in onDestroy when there's a setter but not getter in the template · Issue #16262 · sveltejs/svelte · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Incorrect prop value in onDestroy when there's a setter but not getter in the template #16262

Open
@raythurnvoid

Description

@raythurnvoid

Describe the bug

When a prop has a setter (for instance <button onclick={() => (checked = !checked)}></button>) but it doesn't have a getter (like <p>{checked}</p>), the value read during onDestroy does not match either the old or the current value of the prop, it's instead read as null.

This happens because the compiler decides to use $.prop to read the prop since it detects a "setter", $.prop "wraps" the prop in a derived but since we never read from it, when we execute onDestroy the derived is still in an "uninitialized" state hence it returns null instead of the correct value.

Reproduction

https://svelte.dev/playground/4fa745c18a3c41e88bda761f37b36783?version=5.34.9

Click count++ twice, the 2nd time the Component is unmounted and onDestroy is called and it will log the incorrect checked value that should be true but is logged as null.

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (32) x64 Intel(R) Core(TM) i9-14900HX
    Memory: 41.79 GB / 63.74 GB
  Binaries:
    Node: 23.5.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 11.0.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.4.0 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Chromium (137.0.3296.93)
    Internet Explorer: 11.0.26100.1882

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.