htmx-auto-refresh-preservation

Preserve form input, focus, scroll, and accordion states during HTMX polling or SSE updates.

2|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/ucirello/sgai --skill htmx-auto-refresh-preservation-ucirello
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: htmx-auto-refresh-preservation
Source: https://github.com/ucirello/sgai/tree/main/cmd/sgai/skel/.sgai/skills/htmx-auto-refresh-preservation
Command: npx skills add https://github.com/ucirello/sgai --skill htmx-auto-refresh-preservation-ucirello

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents the loss of user interaction state (like form inputs, scroll positions, and accordion states) in HTMX applications that use automatic content refreshing via polling or Server-Sent Events.

Core Features & Use Cases

  • State Preservation: Ensures user interactions are not lost during frequent DOM updates.
  • Idiomorph Integration: Leverages Idiomorph morph swaps for intelligent DOM updates.
  • Use Case: When building a live dashboard with HTMX that polls for updates every few seconds, this skill ensures that users can still type into input fields or keep accordion sections expanded without their state resetting on each refresh.

Quick Start

Apply the htmx-auto-refresh-preservation skill to your HTMX project to maintain user state during automatic updates.

Frequently Asked Questions about htmx-auto-refresh-preservation

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

FAQPage Schema
How do I prevent HTMX polling from resetting form inputs and focus?

To prevent HTMX polling from resetting form inputs and focus, implement Idiomorph morph swaps. This approach intelligently updates the DOM while preserving user interaction state, including active element focus and input values, during automatic content refreshes.

Why does my HTMX auto-refresh make the page scroll jump?

Your HTMX auto-refresh makes the page scroll jump because standard DOM replacements destroy and recreate elements, losing scroll positions. Implementing Idiomorph morph swaps addresses this by updating existing elements in place rather than replacing them entirely.

How do I keep accordion sections expanded during HTMX SSE updates?

To keep accordion sections expanded during HTMX SSE updates, apply Idiomorph morph swaps with specific configurations. This maintains accordion states and other user interaction data during Server-Sent Events without resetting the DOM structure.

Does Idiomorph work with HTMX to preserve state on live dashboards?

Yes, Idiomorph works with HTMX to preserve state on live dashboards. It leverages morph swaps to ensure frequent polling updates do not disrupt user activities like typing into input fields or keeping accordion sections expanded.

What is the best way to stop select boxes from closing on HTMX refresh?

The best way to stop select boxes from closing on HTMX refresh is to use Idiomorph morph swaps. This technique preserves the active element focus and select box state during automatic DOM updates triggered by polling or SSE.