Skip to content

Commit

Permalink
fix: ensure reactive graph is fully traversed in the marking phase fo…
Browse files Browse the repository at this point in the history
…r non-runes mode (#13059)

* fix: ensure signal status is set in legacy mode

fixes #13051

* add (failing) test

* alternative fix

* add changeset

* alternative fix

* add comment

---------

Co-authored-by: Rich Harris <[email protected]>
Co-authored-by: Dominic Gannaway <[email protected]>
  • Loading branch information
3 people authored Sep 1, 2024
1 parent cf6b64c commit d776e52
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/angry-weeks-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure reactive graph is fully traversed in the marking phase for non-runes mode
9 changes: 8 additions & 1 deletion packages/svelte/src/internal/client/reactivity/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
UNOWNED,
CLEAN,
INSPECT_EFFECT,
HEAD_EFFECT
HEAD_EFFECT,
MAYBE_DIRTY
} from '../constants.js';
import { set } from './sources.js';
import * as e from '../errors.js';
Expand Down Expand Up @@ -281,6 +282,12 @@ export function legacy_pre_effect_reset() {
for (var token of context.l.r1) {
var effect = token.effect;

// If the effect is CLEAN, then make it MAYBE_DIRTY. This ensures we traverse through
// the effects dependencies and correctly ensure each dependency is up-to-date.
if ((effect.f & CLEAN) !== 0) {
set_signal_status(effect, MAYBE_DIRTY);
}

if (check_dirtiness(effect)) {
update_effect(effect);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
import { writable } from 'svelte/store';
import { store } from './state.js';
export let value;
const copy = writable(value);
$: {
copy.set(value);
store.set({ value });
}
</script>

<p>{$copy}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
import { store } from './state.js';

export default test({
html: '<p>0</p><button>1</button>',

before_test() {
store.set({ value: 0 });
},

async test({ assert, target }) {
const button = target.querySelector('button');
flushSync(() => button?.click());

assert.htmlEqual(target.innerHTML, '<p>1</p><button>1</button>');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { store } from './state.js';
import Child from './Child.svelte';
</script>

<Child value={$store.value} />

<button on:click={() => store.set({ value: 1 })}>1</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { writable } from 'svelte/store';

export const store = writable({ value: 0 });

0 comments on commit d776e52

Please sign in to comment.