Maybe the most idiomatic way to implement this pattern with modals in Svelte 5 is to use snapshots. That may suffice to capture the variables the closure needs into a persisted context.
Discussion
In fact it doesn't, you have to re-assign the variable in order to break reactivity
Dang.
Interestingly, I did try putting a `const newValue = value` inside the callback body in your example, and even that didn't work.
It seems like the Svelte compiler should undefine functions in component bodies, to be thorough, since those functions lose their captured context. Then everything in a component would be tied to its lifecycle, not just some things.
Maybe doing that with functions has other problems, though.
The problem is that svelte is trying to re-invent garbage collection. It seems to me like you could just... let stuff be defined, and it would disappear when everything that holds a reference to it gets collected.