From 013311388c4708414ddc2ca9dbe9b40be0ff0e4a Mon Sep 17 00:00:00 2001 From: GustavBW Date: Fri, 4 Oct 2024 20:48:02 +0200 Subject: [PATCH 1/2] Update signal.ts --- packages/solid/src/reactive/signal.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/solid/src/reactive/signal.ts b/packages/solid/src/reactive/signal.ts index 121c44ea0..0e7cde0c2 100644 --- a/packages/solid/src/reactive/signal.ts +++ b/packages/solid/src/reactive/signal.ts @@ -963,12 +963,15 @@ export function on( /** * Runs an effect only after initial render on mount - * @param fn an effect that should run only once on mount + * @param fn an effect that should run only once on mount. It can return a function to be run on cleanup. * * @description https://docs.solidjs.com/reference/lifecycle/on-mount */ -export function onMount(fn: () => void) { - createEffect(() => untrack(fn)); +export function onMount(fn: () => (void | (() => void))) { + createEffect(() => untrack(() => { + const toRunOnCleanup = fn() + if (toRunOnCleanup) onCleanup(toRunOnCleanup) + })); } /** From d6e2d7dfb2d1a6941661b97a206b394171f67a25 Mon Sep 17 00:00:00 2001 From: GustavBW Date: Fri, 4 Oct 2024 21:03:28 +0200 Subject: [PATCH 2/2] Update signal.ts --- packages/solid/src/reactive/signal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/solid/src/reactive/signal.ts b/packages/solid/src/reactive/signal.ts index 0e7cde0c2..19ddbb3bc 100644 --- a/packages/solid/src/reactive/signal.ts +++ b/packages/solid/src/reactive/signal.ts @@ -969,8 +969,8 @@ export function on( */ export function onMount(fn: () => (void | (() => void))) { createEffect(() => untrack(() => { - const toRunOnCleanup = fn() - if (toRunOnCleanup) onCleanup(toRunOnCleanup) + const toRunOnCleanup = fn(); + if (toRunOnCleanup) onCleanup(toRunOnCleanup); })); }