← Back to xhtmlx

Migration Guide

How to upgrade between xhtmlx versions. Use the CLI tool for automated migration.

Automated Migration

The fastest way to migrate is the built-in CLI tool:

npx xhtmlx-migrate --from=1 --to=2 src/

Preview changes first with --dry-run, or rollback with --reverse.

# Preview changes without modifying files
npx xhtmlx-migrate --dry-run --from=1 --to=2 src/

# Rollback if something breaks
npx xhtmlx-migrate --from=1 --to=2 --reverse src/

# Show all migration rules
npx xhtmlx-migrate --list-rules --from=1 --to=2

v1 → v2

Attribute Renames RENAME

v1 (old)v2 (new)Notes
xh-bindxh-modelTwo-way binding renamed for clarity
xh-loadingxh-indicatorLoading indicator renamed to match htmx convention

Value Changes RENAME

Attributev1 valuev2 value
xh-swap"replace""outerHTML"

New Requirements BREAKING

ChangeDetails
xh-ws requires xh-triggerWebSocket elements now need explicit xh-trigger="message". Previously auto-triggered.
Strict equality for xh-modelRadio buttons and selects use === instead of ==. Ensure data types match option values (e.g. "1" not 1).

New Features in v2 NEW

How to Migrate Safely

  1. Run dry-run firstnpx xhtmlx-migrate --dry-run --from=1 --to=2 src/
  2. Review the changes — check each file in the output
  3. Commit your current state — so you can revert via git
  4. Apply the migrationnpx xhtmlx-migrate --from=1 --to=2 src/
  5. Test your app — run your tests, check the UI
  6. If something breaks — either git revert or npx xhtmlx-migrate --reverse --from=1 --to=2 src/

UI Version Switching

For zero-downtime deployment, use xhtmlx.switchVersion() instead of migrating HTML files:

// Deploy new templates alongside old ones
// /ui/v1/templates/...  (current)
// /ui/v2/templates/...  (new)

// Switch all widgets to v2 templates
xhtmlx.switchVersion("v2");

// Rollback if needed
xhtmlx.switchVersion("v1");

This changes the template prefix at runtime without modifying any HTML files. See switchVersion API docs.