mirror of https://github.com/sveltejs/svelte
fix: more informative error when effects run in an infinite loop (#16405)
* update effect_update_depth_exceeded docs * log update locations * remove dev_effect_stack stuff, it's not very helpful * tidy up * test * fix test * changeset * fixpull/16406/head
parent
09c9a3c165
commit
a67b5862f1
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: more informative error when effects run in an infinite loop
|
@ -0,0 +1,21 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
mode: ['client', 'hydrate'],
|
||||||
|
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
|
||||||
|
test({ assert, errors }) {
|
||||||
|
const [button] = document.querySelectorAll('button');
|
||||||
|
|
||||||
|
try {
|
||||||
|
flushSync(() => button.click());
|
||||||
|
} catch (e) {
|
||||||
|
assert.equal(errors.length, 1); // for whatever reason we can't get the name which should be UpdatedAtError
|
||||||
|
assert.ok(/** @type {Error} */ (e).message.startsWith('effect_update_depth_exceeded'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
let condition = $state(false);
|
||||||
|
let count = $state(0);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (condition) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button onclick={() => condition = !condition}>toggle</button>
|
Loading…
Reference in new issue