{"record":{"id":"f8e390af6975496b","repo":"sveltejs/svelte","slug":"flush-sync-in-effect","errorCode":"flush_sync_in_effect","errorMessage":"flush_sync_in_effect\nCannot use `flushSync` inside an effect\nhttps://svelte.dev/e/flush_sync_in_effect","messagePattern":"flush_sync_in_effect\nCannot use `flushSync` inside an effect\nhttps://svelte\\.dev/e/flush_sync_in_effect","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/internal/client/errors.js","lineNumber":263,"sourceCode":"\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/effect_update_depth_exceeded`);\n\t}\n}\n\n/**\n * Cannot use `flushSync` inside an effect\n * @returns {never}\n */\nexport function flush_sync_in_effect() {\n\tif (DEV) {\n\t\tconst error = new Error(`flush_sync_in_effect\\nCannot use \\`flushSync\\` inside an effect\\nhttps://svelte.dev/e/flush_sync_in_effect`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/flush_sync_in_effect`);\n\t}\n}\n\n/**\n * Cannot commit a fork that was already discarded\n * @returns {never}\n */\nexport function fork_discarded() {\n\tif (DEV) {\n\t\tconst error = new Error(`fork_discarded\\nCannot commit a fork that was already discarded\\nhttps://svelte.dev/e/fork_discarded`);\n\n\t\terror.name = 'Svelte error';\n\n\t\tthrow error;\n\t} else {\n\t\tthrow new Error(`https://svelte.dev/e/fork_discarded`);\n\t}\n}","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/sveltejs/svelte/blob/20b341f10048cf1016a2028ac7eee5595cfef6a5/packages/svelte/src/internal/client/errors.js#L245-L281","documentation":"Thrown when flushSync() is called from inside a running effect. flushSync forces synchronous flush of pending updates; calling it from within an effect that is itself part of the flush cycle would re-enter the flusher and corrupt Svelte's internal batch state, so it is rejected.","triggerScenarios":"Calling the imported flushSync from 'svelte' (or this lib) directly inside a $effect callback, an $effect.pre, or a function synchronously invoked from one while the effect is flushing. The guard detects re-entrant sync flushing.","commonSituations":"Calling flushSync to force DOM measurement inside an effect; wrapping test assertions in flushSync within a component effect; porting legacy afterUpdate code that used tick()/flush synchronously into a runes effect.","solutions":["Remove the flushSync call — by the time the effect runs, scheduling is already managed by Svelte; queue the work via a microtask or $effect instead.","If you need to ensure updates are applied, use await tick() rather than flushSync.","Move the flushSync call to an event handler or onMount where no effect is mid-flush."],"exampleFix":"// before\nimport { flushSync } from 'svelte';\n$effect(() => {\n  flushSync(); // re-entrant flush\n  measureNode();\n});\n\n// after\nimport { tick } from 'svelte';\n$effect(() => {\n  tick().then(() => measureNode());\n});","handlingStrategy":"validation","validationCode":"// Do not call flushSync inside an effect. Replace with tick():\nimport { tick } from 'svelte';\n// $effect(() => { tick().then(() => measure()); });\n// If you must flush synchronously, do it from an event handler, not an effect.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call flushSync from inside a $effect, $effect.pre, or $inspect callback.","Use await tick() for post-update measurement instead.","If you need synchronous DOM reads after a write, queueMicrotask is safer than flushSync."],"tags":["svelte","runes","effects","flushsync","reactivity"],"backgroundTag":null,"analyzedSha":"20b341f10048cf1016a2028ac7eee5595cfef6a5","analyzedAt":"2026-08-12T23:37:30.399Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}