solid-core-lifecycle

Explain SolidJS lifecycle management with onMount and onCleanup for resource disposal.

Updated Jan 4, 2026
One-click install
npx skills add https://github.com/vallafederico/solid-ai-rules --skill solid-core-lifecycle
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: solid-core-lifecycle
Source: https://github.com/vallafederico/solid-ai-rules/tree/main/.claude/skills/solid-core-lifecycle
Command: npx skills add https://github.com/vallafederico/solid-ai-rules --skill solid-core-lifecycle

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers understand and correctly implement SolidJS lifecycle methods like onMount and onCleanup to manage component behavior, prevent memory leaks, and ensure proper resource disposal.

Core Features & Use Cases

  • Component Mounting (onMount): Execute code after a component is added to the DOM, ideal for DOM manipulation and third-party library initialization.
  • Resource Cleanup (onCleanup): Register functions to run when a component unmounts or an effect is disposed, crucial for preventing memory leaks by cleaning up event listeners, subscriptions, and intervals.
  • Effect Lifecycle Management: Understand how cleanup functions within createEffect work before re-execution or disposal.
  • Use Case: Ensure that an event listener attached in onMount is correctly removed in onCleanup when the component is no longer visible, preventing potential errors and memory leaks.

Quick Start

Explain how to use onMount to focus an input element after a SolidJS component has been rendered.

Frequently Asked Questions about solid-core-lifecycle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use onMount and onCleanup to manage SolidJS component lifecycle?

SolidJS lifecycle management uses `onMount` for DOM access post-render and `onCleanup` for resource disposal. You register cleanup functions to run when a component unmounts or an effect is disposed, preventing memory leaks from lingering event listeners or subscriptions.

Why does my SolidJS ref return undefined outside onMount?

Accessing refs outside `onMount` is an anti-pattern because the DOM element is not yet rendered. SolidJS lifecycle management requires `onMount` to execute code after the component is added to the DOM, ensuring DOM manipulation and third-party library initialization target valid elements.

What's the best way to handle event listeners and intervals in SolidJS to prevent memory leaks?

The best way to prevent memory leaks in SolidJS is registering cleanup logic within `onCleanup`. Attach event listeners and start intervals in `onMount`, then remove listeners and clear intervals inside `onCleanup` to ensure proper resource disposal when the component unmounts.

How does effect cleanup work in SolidJS createEffect before re-execution?

SolidJS effect lifecycle management runs cleanup functions within `createEffect` before re-execution or disposal. This ensures that previous effect resources are correctly disposed of, separating component cleanup from effect cleanup to maintain reactivity without leaking subscriptions.

Can I use AbortController with SolidJS onCleanup for managing subscriptions?

Yes, AbortController is a best practice for managing subscriptions in SolidJS. You initialize the controller during component mounting and call `abort()` within `onCleanup` to simultaneously cancel fetch requests and subscriptions upon component unmounting or effect disposal.

When should I use onCleanup in SolidJS component management?

You should use `onCleanup` in SolidJS whenever a component creates resources like event listeners, subscriptions, or intervals. It runs during component unmounting or effect disposal, serving as the primary mechanism to prevent memory leaks and ensure proper resource cleanup.