From 9a196ac54da69747ed96df14a58eae1d21796a3a Mon Sep 17 00:00:00 2001 From: Vishal Kumar Singh Date: Sat, 16 May 2026 12:28:37 +0530 Subject: [PATCH] Clarify onMount runs on reactive tree creation, not DOM insertion Co-authored-by: Cursor --- src/routes/reference/lifecycle/on-mount.mdx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/routes/reference/lifecycle/on-mount.mdx b/src/routes/reference/lifecycle/on-mount.mdx index 247d34265..5f6827617 100644 --- a/src/routes/reference/lifecycle/on-mount.mdx +++ b/src/routes/reference/lifecycle/on-mount.mdx @@ -52,6 +52,14 @@ Non-tracking function executed once on mount. - By the time `onMount` runs, refs have already been assigned. - Returning a function from `fn` does not register cleanup. Use [`onCleanup`](/reference/lifecycle/on-cleanup) inside `onMount` when cleanup is needed. +:::note +"Mounted" in Solid refers to when a component is rendered within the reactive tree, not when it is physically inserted into the DOM. +If you store JSX in a variable before conditionally rendering it, `onMount` runs when that JSX is evaluated, even if the elements have not yet been added to the visible page. +Similarly, [`onCleanup`](/reference/lifecycle/on-cleanup) runs based on the reactive ownership tree rather than DOM removal. + +For cases where you need to detect actual DOM insertion or removal, consider using a [`ref`](/concepts/refs) callback or the [Lifecycle primitives from solid-primitives](https://github.com/solidjs-community/solid-primitives/tree/main/packages/lifecycle). +::: + ## Examples ### Access a ref after mount