Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component unmount results in undefined variables in closures #15325

Closed
staab opened this issue Feb 17, 2025 · 3 comments
Closed

Component unmount results in undefined variables in closures #15325

staab opened this issue Feb 17, 2025 · 3 comments

Comments

@staab
Copy link

staab commented Feb 17, 2025

Describe the bug

If a function which closes over state received via props is called after that component unmounts, the closed over value becomes undefined. This is a breaking change compared to svelte 4, but I don't see it called out in the migration guide or anywhere else in the documentation. Fixing this behavior to allow passing of closures around requires awkward/annoying/error prone value re-assignment.

Reproduction

Here is a Stack Overflow question that goes into more detail: https://stackoverflow.com/questions/79446266/svelte-5-props-are-undefined-after-unmount

Reproduction source code: https://github.com/staab/svelte5-closure-bug
Reproduction demo: https://svelte5-closure-bug.onrender.com/

Logs

init 1
update undefined
value is undefined: undefined

System Info

System:
    OS: macOS 15.3
    CPU: (8) arm64 Apple M1
    Memory: 74.69 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.6 - ~/.nvm/versions/node/v18.20.6/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v18.20.6/bin/npm
    pnpm: 9.15.0 - ~/Library/pnpm/pnpm
    bun: 1.2.2 - ~/.nvm/versions/node/v18.20.6/bin/bun
  Browsers:
    Brave Browser: 132.1.74.50
    Chrome: 133.0.6943.98
    Safari: 18.3
  npmPackages:
    svelte: ^5.0.0 => 5.20.1

Severity

annoyance (additional context: I was a big fan of svelte 4. For this reason and others, I don't plan to use svelte for any new projects)

@staab
Copy link
Author

staab commented Feb 17, 2025

So far this is the cleanest solution I've found to my problem:

const closure = ((value) => {
  console.log(value)
}).bind(undefined, value)

But I don't love this, for obvious reasons.

@Prinzhorn
Copy link
Contributor

#14707 also #14725 #14911 #14950

@dummdidumm
Copy link
Member

Closing as duplicate of #14725 (the underlying reason is the same)

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2025
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

No branches or pull requests

3 participants