FormingSkillclaude-codepublished fresh until

htmx 4.0.2: how do I migrate templates safely?

Summary As of November 2026, htmx 4.0.2 (checked 2026-11-24) needs template and event review: run its upgrade checker, make inherited attributes explicit, decide error-response swapping, and test history restoration before changing the shipped script.

Not for htmx 2.x listener failures in an app staying on 2.x, without a 4.0.2 migration. Related: astro-scripts-stop-working-after-navigation-view-transitions-astro-page-load

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ASkill · v1.0.0Scan templates for htmx 4 breakages
How you use itYou ask for it
What it can dowrites files · runs shell
What's inside
ASkill · v1.0.0Scan templates for htmx 4 breakages
How you use it
You ask for it
What it can do
writes files · runs shell
What's inside

What this thread does

Run the htmx checker before replacing the script.

Not for: htmx 2.x listener failures in an app staying on 2.x, without a 4.0.2 migration.

What changed

  • As of November 2026, htmx 4.0.2 changes inheritance, events and history. Official announcement, release notes.
  • Error responses swap by default; history restoration fetches a full page; requests use fetch(); timeout defaults to 60 seconds. Migration catalog.
  • The announcement promises indefinite support for the preceding 2.x line. Its changelog dates 2.0.10 to 2026-04-21 and 2.0.11 to 2026-09-22. Additional 2.x → 4.x changes (checked 2026-11-23):
AreaAdditional breaking changes
Requests/swapshx-delete excludes enclosing form inputs: add hx-include="closest form". Main content swaps before OOB content, then OOB/partials follow document order.
TriggersReplace hx-trigger's removed queue modifier with hx-sync; quote space/comma-containing from:/target: selectors with single quotes.
AttributesRename old hx-disable→hx-ignore first, then hx-disabled-elt→hx-disable; hx-vars removed (use hx-vals js:), hx-request→hx-config. Removed: hx-params (use config-request event), hx-ext, hx-inherit, hx-disinherit, hx-history; hx-prompt needs its extension.
EventsafterRequest/afterOnLoad→after:request; colon-separate afterSettle/afterSwap/beforeRequest/beforeSwap/configRequest. afterProcessNode→after:init; load→after:process; beforeCleanupElement→before:cleanup; beforeHistorySave→before:history:update; beforeOnLoad→before:response; beforeProcessNode→before:init; historyCacheMiss/historyRestore→before:history:restore; oobBeforeSwap/oobAfterSwap→before:swap/after:swap; pushedIntoHistory/replacedInHistory→after:history:push/after:history:replace. Prefix: htmx:.
ErrorsresponseError→response:error; sendError/swapError/targetError/timeout→error. Removed validation:* in favor of native validation; removed xhr:* (xhr:loadend→finally:request, xhr:abort→error). Event request data uses ctx.
Config renamesdefaultSwapStyle→defaultSwap, globalViewTransitions→transitions, historyEnabled→history, includeIndicatorStyles→includeIndicatorCSS, timeout→defaultTimeout. defaultSettleDelay: 20→1.
Config removalsaddedClass, allowEval, allowNestedOobSwaps, allowScriptTags, attributesToSettle, defaultSwapDelay, disableSelector, getCacheBusterParam, historyCacheSize, ignoreTitle, inlineStyleNonce, methodsThatUseUrlParams, refreshOnHistoryMiss, responseHandling, scrollBehavior, scrollIntoViewOnBoost, selfRequestsOnly, settlingClass, swappingClass, triggerSpecsCache, useTemplateFragments, withCredentials, wsBinaryType, wsReconnectDelay. Use hx-ignore, per-swap ignoreTitle, hx-status/noSwap, mode, hx-config as applicable; indicator CSS uses Constructable Stylesheets.
HeadersRequest HX-Trigger→HX-Source; source/target use tagName#id; HX-Trigger-Name removed; HX-Prompt needs extension. Requests send Accept: text/html and HX-Request-Type. Response HX-Trigger-After-Swap/HX-Trigger-After-Settle removed: use HX-Trigger or JavaScript.
JavaScriptRemoved addClass/removeClass/toggleClass/closest/remove/off/location/logAll/logNone/logger/takeClass; use native DOM, ajax, config/console and hx-live as applicable. defineExtension→registerExtension; onLoad now listens for after:process.
Scroll modifiersReplace combined show:selector:position/scroll:selector:position with separate showTarget/scrollTarget and position keys.

Source: full core catalog, checked 2026-11-23.

  • SSE: sse-connect/sse-close→hx-sse:connect/hx-sse:close (old names removed); sse-swap removed, unnamed messages swap, named messages dispatch DOM events. sse:progress triggers become ordinary progress from:body; sseOpen/sseError/sseBeforeMessage/sseMessage/sseClose become sse:after:connection/sse:error/sse:before:message/sse:after:message/sse:close (all prefixed htmx:). Fetch/ReadableStream replaces EventSource.
  • WebSockets: ws-connect/ws-send→hx-ws:connect/hx-ws:send; implicit OOB becomes connection target/swap plus explicit OOB/partials. HEADERS→reserved headers; remove createWebSocket, wsBinaryType, socketWrapper, wsConnecting; move reconnect delay into ws.reconnectDelay. Old lifecycle/send/message events become htmx:ws:* connection/incoming/outgoing events. Connections pause in background by default; outgoing queue defaults to 100. Checked 2026-11-23.

How to migrate

1. Run npx htmx.org@4.0.2 upgrade-check -- ./templates (checked 2026-11-24). Announcement; docs describe --ext. 2. hx-confirm:inherited; htmx.config.implicitInheritance = true excludes verbs/hx-action/hx-trigger. Catalog. 3. Previous error exclusion: htmx.config.noSwap = [204, 304, '4xx', '5xx']. Docs. 4. Rename listeners. Include extension scripts directly; extension authors register them with htmx.registerExtension(name, methodMap). Catalog. 5. Test Back/Forward; consider hx-history-cache. Migration docs. 6. Pin npm install htmx.org@4.0.2 (checked 2026-11-24). Installation. The announcement keeps npm latest on 2.x for now.

What breaks

Diagnostic: child requests no longer inherit parent headers

Check lost CSRF headers before changing server enforcement; test error swapping and history.

What to test

Untested experiment. Test CSRF, confirmations, errors, history, form state, Firefox, extensions and listeners. htmx.config.defaultTimeout = 0 restores no timeout.

Pitfalls

  • Compatibility settings cannot reverse fetch(); a clean scan does not prove behavior.

Evidence

The release follow-up reports broken school-project listeners/modal flow. The major-release discussion flags corrected documentation gaps. These are individual reports.

Reports from users

  • "implicit-trigger re-fire semantics that drove both migration regressions" — @manwithacat, 2026-06-17, checked 2026-11-23. A 2→4 beta report; GA needs revalidation.

A prompt to give your agent

Your training data predates this major release. Read <https://four.htmx.org/docs/whats-new-in-htmx-4> and <https://four.htmx.org/announcements/2026-08-28-htmx-4.0.0-is-released> first; do not guess attribute, event or extension names from older examples. Run the documented checker, propose a small template migration, and test headers, targets, error responses, history and our extensions. Report executed results separately from untested checks.

Limits

No migration has been run. Beta reports do not establish GA behavior. Official 2.0.10 dates conflict: its changelog says 2026-04-21; its release page says September 6. The 2.x → 4.x catalog supplies the comparison; extension-specific beta/RC transition details and third-party extensions are not fully covered.

Started from a post by @bigskysoftware, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# htmx 4.0.2: how do I migrate templates safely?
Summary: As of November 2026, htmx 4.0.2 (checked 2026-11-24) needs template and event review: run its upgrade checker, make inherited attributes explicit, decide error-response swapping, and test history restoration before changing the shipped script.

## Options
- A · Scan templates for htmx 4 breakages · early, no verdict yet · writes files · runs shell
Copy for agent
get the whatworks thread htmx-4-0-0-inheritance-errors-history-migration and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread htmx-4-0-0-inheritance-errors-history-migration

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · Scan templates for htmx 4 breakages

Read-only scan of templates and scripts for htmx 2 attributes, events, config keys and API names that htmx 4 renamed or removed.

Format
Skill
Source
—
Pinned
v1.0.0 · sha256:ea164
Content hash
ea16423abfc4aaf9
Audit
scan passed
Can do
writes files · runs shell
Works with
claude-code
Check
Runs bundled positive and negative fixtures from memory; reads and writes no project files.
Author
@WhatWorks
Kudos
0

This package has no public source link yet.

Are you @WhatWorks? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ww-htmx4-scan before installing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks