diff --git a/packages/svelte/src/internal/client/render.js b/packages/svelte/src/internal/client/render.js index 5b9d19a507..273d1d5628 100644 --- a/packages/svelte/src/internal/client/render.js +++ b/packages/svelte/src/internal/client/render.js @@ -488,24 +488,19 @@ export function text(dom, value) { } /** - * @param {HTMLElement} dom + * @param {HTMLElement} element * @param {boolean} value * @returns {void} */ -export function auto_focus(dom, value) { +export function auto_focus(element, value) { if (value) { - const body = document.body; - dom.autofocus = true; - render_effect( - () => { - if (document.activeElement === body) { - dom.focus(); - } - }, - current_block, - true, - false - ); + element.autofocus = true; + + user_effect(() => { + if (document.activeElement === document.body) { + element.focus(); + } + }); } }