What is Nostr?
buttercat1791 / Michael J
npub1wqf…qsyn
2025-02-17 20:29:51
in reply to nevent1q…pykk

buttercat1791 on Nostr: Taking a look at this...it's a really odd pattern, but it also doesn't surprise me ...

Taking a look at this...it's a really odd pattern, but it also doesn't surprise me that it's not working.

The `value` prop is: a) only scoped to `Component1`, and b) never passed to `Component2`. Since the `state` object on `+page.svelte` is redeclared, `value` doesn't live there, either. It looks to me like Svelte is doing the natural thing and letting `value` be destroyed with its owner (i.e., `Component1`).

Interestingly, the `closure` function seems to outlive its component. As your example solution suggests, copying `value` into the closure's scope ensures `value` has the same lifespan as `closure`.

How come this worked in Svelte 4? I'm trying to understand what Svelte/JS is doing with the references under the hood that would explain the behavior.
Author Public Key
npub1wqfzz2p880wq0tumuae9lfwyhs8uz35xd0kr34zrvrwyh3kvrzuskcqsyn