diff --git a/.changeset/smooth-rings-rush.md b/.changeset/smooth-rings-rush.md
new file mode 100644
index 0000000000..56185fd2aa
--- /dev/null
+++ b/.changeset/smooth-rings-rush.md
@@ -0,0 +1,5 @@
+---
+"svelte": patch
+---
+
+fix: improve internal render effect sequencing
diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js
index 4db42363cd..4c45dd0f22 100644
--- a/packages/svelte/src/internal/client/runtime.js
+++ b/packages/svelte/src/internal/client/runtime.js
@@ -519,16 +519,19 @@ export function schedule_effect(signal, sync) {
const target_block = signal.block;
const is_pre_effect = (flags & PRE_EFFECT) !== 0;
let target_signal;
+ let target_signal_level;
let is_target_pre_effect;
let i = length;
while (true) {
target_signal = current_queued_pre_and_render_effects[--i];
- if (target_signal.l <= target_level) {
+ target_signal_level = target_signal.l;
+ if (target_signal_level <= target_level) {
if (i + 1 === length) {
should_append = true;
} else {
is_target_pre_effect = (target_signal.f & PRE_EFFECT) !== 0;
if (
+ target_signal_level < target_level ||
target_signal.block !== target_block ||
(is_target_pre_effect && !is_pre_effect)
) {
diff --git a/packages/svelte/tests/runtime-runes/samples/if-dependency-order-2/Seo.svelte b/packages/svelte/tests/runtime-runes/samples/if-dependency-order-2/Seo.svelte
new file mode 100644
index 0000000000..6176f3eefc
--- /dev/null
+++ b/packages/svelte/tests/runtime-runes/samples/if-dependency-order-2/Seo.svelte
@@ -0,0 +1,9 @@
+
+
+
{post.title}
diff --git a/packages/svelte/tests/runtime-runes/samples/if-dependency-order-2/_config.js b/packages/svelte/tests/runtime-runes/samples/if-dependency-order-2/_config.js new file mode 100644 index 0000000000..83b58d0f7b --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/if-dependency-order-2/_config.js @@ -0,0 +1,22 @@ +import { flushSync } from 'svelte'; +import { test } from '../../test'; + +export default test({ + async test({ assert, target, window }) { + const [btn1] = target.querySelectorAll('button'); + + assert.htmlEqual(window.document.head.innerHTML, ``); + + flushSync(() => { + btn1.click(); + }); + + assert.htmlEqual(window.document.head.innerHTML, `