htmx-auto-refresh-preservation

Preserve user state during HTMX auto-refresh with Idiomorph morph swaps.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Auto-refreshing HTMX regions commonly reset focus, close selects, collapse details/accordions, and jump scroll positions on every update. This Skill provides a prescriptive setup using Idiomorph morph swaps and event hooks so polling or SSE updates do not disrupt in-progress user interactions.

Core Features & Use Cases

  • State-Safe Morph Swaps: Enforces morph:innerHTML/outerHTML with hx-ext="morph" and Idiomorph defaults (ignoreActive, ignoreActiveValue) to preserve focus and input values.
  • UI State Preservation: Prevents <details> from collapsing via beforeAttributeUpdated and restores scroll positions with htmx:beforeSwap/afterSwap handlers.
  • Robust Interaction Patterns: Offers selective morph exclusion and conditional polling to avoid jarring updates while users type, select, or drag.
  • Use Case: A dashboard panel that polls every 2s for updated job statuses while a user edits a form and reads logs in a scrollable container; inputs stay focused, selects remain open, details stay expanded, and scroll positions are preserved.

Quick Start

Enable hx-ext="morph", include idiomorph-ext.min.js, set Idiomorph defaults for ignoreActive and ignoreActiveValue, use morph:innerHTML on polling regions, and add callbacks to preserve details and scroll positions.

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 focus and form inputs during auto-refresh?

To prevent HTMX polling from resetting focus and inputs, use morph swaps with Idiomorph defaults like ignoreActive and ignoreActiveValue to preserve user state during DOM updates.

Why does my HTMX SSE update close selects and collapse details elements on every refresh?

HTMX SSE updates close selects and collapse details because standard swaps replace the entire DOM subtree, destroying state; beforeAttributeUpdated callbacks with morph swaps prevent this collapse.

What's the best way to preserve scroll position in an HTMX auto-refresh container?

The best way to preserve scroll position during HTMX auto-refresh is implementing htmx:beforeSwap and afterSwap event handlers alongside Idiomorph morph swaps to restore scroll offsets after DOM updates.

How do I set up Idiomorph morph swaps for HTMX polling regions?

Set up Idiomorph morph swaps by including idiomorph-ext.min.js, enabling hx-ext="morph", applying morph:innerHTML or morph:outerHTML on polling regions, and configuring Idiomorph defaults for state preservation.

Can I temporarily disable HTMX auto-refresh while a user is typing or interacting with a form?

Yes, you can pause HTMX auto-refresh during user interaction by implementing conditional polling and selective morph exclusion to avoid jarring updates while users type, select, or drag elements.