Skip to content

Commit

Permalink
fix: ensure legacy run utility does not cause cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Oct 17, 2024
1 parent f579a3b commit 99c0c48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-pugs-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure legacy run utility does not cause cycles
18 changes: 16 additions & 2 deletions packages/svelte/src/legacy/legacy-client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
/** @import { ComponentConstructorOptions, ComponentType, SvelteComponent, Component } from 'svelte' */
import { DIRTY, MAYBE_DIRTY } from '../internal/client/constants.js';
import { user_pre_effect } from '../internal/client/reactivity/effects.js';
import { mutable_source, set } from '../internal/client/reactivity/sources.js';
import { hydrate, mount, unmount } from '../internal/client/render.js';
import { component_context, flush_sync, get } from '../internal/client/runtime.js';
import {
active_effect,
component_context,
flush_sync,
get,
set_signal_status
} from '../internal/client/runtime.js';
import { lifecycle_outside_component } from '../internal/shared/errors.js';
import { define_property, is_array } from '../internal/shared/utils.js';

Expand Down Expand Up @@ -169,7 +176,14 @@ class Svelte4Component {
* @returns {void}
*/
export function run(fn) {
user_pre_effect(fn);
user_pre_effect(() => {
fn();
var effect = /** @type {import('#client').Effect} */ (active_effect);
// If the effect is immediately made dirty again, mark it as maybe dirty to emulate legacy behaviour
if ((effect.f & DIRTY) !== 0) {
set_signal_status(effect, MAYBE_DIRTY);
}
});
}

/**
Expand Down

0 comments on commit 99c0c48

Please sign in to comment.