From 2afb88848502e69d9e24498ddcaa5f9779284f78 Mon Sep 17 00:00:00 2001 From: weaseldotro <1822852+weaseldotro@users.noreply.github.com> Date: Tue, 20 Oct 2020 11:09:33 +0300 Subject: [PATCH] fix(ComposedModal): remove bx--body--with-modal-open from body classes after destroy When onMount is async, the returned function is not executed: https://github.com/sveltejs/svelte/issues/4927 Because the class is not remove from the body, the code should be moved to a onDestroy function. --- src/ComposedModal/ComposedModal.svelte | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ComposedModal/ComposedModal.svelte b/src/ComposedModal/ComposedModal.svelte index 47f1c36e..5d5eaed5 100644 --- a/src/ComposedModal/ComposedModal.svelte +++ b/src/ComposedModal/ComposedModal.svelte @@ -47,6 +47,7 @@ setContext, onMount, afterUpdate, + onDestroy, } from "svelte"; const dispatch = createEventDispatcher(); @@ -79,12 +80,12 @@ onMount(async () => { await tick(); focus(); - - return () => { - document.body.classList.remove("bx--body--with-modal-open"); - }; }); + onDestroy(() => { + document.body.classList.remove("bx--body--with-modal-open"); + }) + afterUpdate(() => { if (opened) { if (!open) {