Skip to content

fix: mark reactions of MAYBE_DIRTY reactions too #16110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
5 changes: 5 additions & 0 deletions .changeset/sour-jars-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: mark reactions of `MAYBE_DIRTY` reactions too
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/reactivity/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function mark_reactions(signal, status) {
set_signal_status(reaction, status);

// If the signal a) was previously clean or b) is an unowned derived, then mark it
if ((flags & (CLEAN | UNOWNED)) !== 0) {
if ((flags & (CLEAN | UNOWNED | MAYBE_DIRTY)) !== 0) {
if ((flags & DERIVED) !== 0) {
mark_reactions(/** @type {Derived} */ (reaction), MAYBE_DIRTY);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
let {config, value = $bindable()} = $props();

$effect.pre(() => {
config;
value = {}
});
</script>

a
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
let {config, value = $bindable()} = $props();

$effect.pre(() => {
config;
value = {}
});
</script>

b
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { flushSync } from 'svelte';
import { test } from '../../test';

export default test({
html: '<button></button> a',
async test({ assert, target }) {
const btn = target.querySelector('button');
flushSync(() => {
btn?.click();
});

assert.htmlEqual(target.innerHTML, `<button></button> b`);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script>
import A from "./A.svelte";
import B from "./B.svelte";

let schema = $state("any");
let value = $state({});

let config = $derived.by(() => {
value;
return schema;
});

let Thing = $derived.by(() => {
return config === "any" ? A : B;
});
</script>

<button onclick={()=>{
schema = "one";
}}></button>

<Thing {config} bind:value/>
Loading