-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Description
Describe the bug
Looks like if models (Source) are wrapped in $derived which contains some kind of caching strategy to reuse wrappers (Target), wrappers looses reactivity.
let cache = new WeakMap<Source, Target>();
let targets = $derived.by(() => {
return sources.map(source => {
let target = cache.get(source);
if(!target) {
target = new Target(source);
cache.set(source, target);
}
return target;
});
});Reproduction
https://svelte.dev/playground/151a2151934544288c5c5a793a09c27a?version=5.0.5
Click "Add source" few times then "Mark all as existing".
All rows should render target: {id} exists=true", instead only latest one (which hasn't been reused in $derived cache) properly updates.
Logs
No response
System Info
System:
OS: macOS 14.6.1
CPU: (8) arm64 Apple M1
Memory: 142.06 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v18.19.0/bin/yarn
npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
pnpm: 8.15.5 - ~/.nvm/versions/node/v18.19.0/bin/pnpm
bun: 1.0.15 - ~/.bun/bin/bun
Watchman: 2023.12.04.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 130.0.6723.69
Safari: 17.6
npmPackages:
svelte: ^5.0.5 => 5.0.5Severity
blocking all usage of svelte
Metadata
Metadata
Assignees
Labels
No labels