chore: add "untracked allows writes" test (#17930)

While we don't officially document it, `untrack` also allows to opt out
of the "unsafe mutation" validation, which is what we test here.

For anyone coming across this: USE WITH CAUTION. This can cause graph
inconsistencies leading to wrong values on initial render

Doing this because we're gonna make use of it ourselves for remote
functions, and this ensures we don't accidentally regress.
pull/17919/head
Simon H 3 days ago committed by GitHub
parent 1ebed68322
commit dcf4865b22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,19 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
// While we don't officially document it, `untrack` also allows to opt out of the "unsafe mutation" validation, which is what we test here
export default test({
html: '<button>0 0 0</button>',
test({ assert, target }) {
const button = target.querySelector('button');
flushSync(() => button?.click());
assert.htmlEqual(
target.innerHTML,
`
<button>1 1 2</button>
`
);
}
});

@ -0,0 +1,14 @@
<script>
import { untrack } from "svelte";
let count = $state(0);
let mirrored = $state(0);
let double = $derived.by(() => {
untrack(() => {
mirrored = count;
});
return count * 2;
})
</script>
<button onclick={() => count++}>{count} {mirrored} {double}</button>
Loading…
Cancel
Save