From ba0eed1d53835d6e04c38b8f9e873edf8f4a69eb Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 23 Feb 2024 16:46:11 -0500 Subject: [PATCH] simplify autofocus --- packages/svelte/src/internal/client/render.js | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) 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(); + } + }); } }