pull/18812/merge
svelte-triage-bot[bot] 2 days ago committed by GitHub
commit 863246240f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: evaluate uninitialized derived values outside their fork batch

@ -681,7 +681,7 @@ export function get(signal) {
var is_new = (derived.f & REACTION_RAN) === 0;
if (is_dirty(derived)) {
if ((derived.v === UNINITIALIZED && !batch_values?.has(derived)) || is_dirty(derived)) {
if (should_connect) {
// set the flag before `update_derived`, so that the derived
// is added as a reaction to its dependencies

@ -0,0 +1,6 @@
<script>
const props = $props();
const klass = (value) => `box ${value}`;
</script>
<button class={klass(props.label)} disabled={props.disabled}>x</button>

@ -0,0 +1,14 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
skip_no_async: true,
test({ assert, target }) {
const [fork, update] = target.querySelectorAll('button');
flushSync(() => fork.click());
flushSync(() => update.click());
assert.htmlEqual(target.innerHTML, '<button>fork</button> <button>update</button>');
}
});

@ -0,0 +1,14 @@
<script>
import { fork } from 'svelte';
import Child from './Child.svelte';
let target = $state(false);
let disabled = $state(false);
</script>
<button onclick={() => fork(() => (target = true))}>fork</button>
<button onclick={() => (disabled = true)}>update</button>
{#if target}
<Child label="a" {disabled} />
{/if}
Loading…
Cancel
Save