Skip to content

Improve moprh exact node matching with scan ahead - #3591

Merged
1cg merged 2 commits into
bigskysoftware:fourfrom
MichaelWest22:morph-scanLimit
Dec 19, 2025
Merged

Improve moprh exact node matching with scan ahead#3591
1cg merged 2 commits into
bigskysoftware:fourfrom
MichaelWest22:morph-scanLimit

Conversation

@MichaelWest22

Copy link
Copy Markdown
Collaborator

Description

Improve morph exact node matching with scan ahead

Rewrote __findBestMatch to use isEqualNode() for better matching of non-ID nodes during morphing.

Key changes:

  • Scan ahead using isEqualNode() to find exact matches for elements without IDs
  • Added htmx.config.morphScanLimit (default: 10) to control how many siblings to scan
  • ID-based matches always continue scanning regardless of limit
  • Stop scanning early when limit is exhausted for non-ID elements (nodeMatchCount === 0)
  • Improved sibling duplicate detection to return null when duplicates found
  • Renamed siblingSoftMatchCount to siblingMatchCount

This significantly improves morphing accuracy for lists of similar elements without IDs, while maintaining performance through configurable scan limits.

Corresponding issue:

Testing

Please explain how you tested this change manually, and, if applicable, what new tests you added. If
you're making a change to just the website, you can omit this section.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@MichaelWest22 MichaelWest22 added the htmx 4 Issues specific to htmx version 4 label Dec 16, 2025
@1cg
1cg merged commit 55227c0 into bigskysoftware:four Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

htmx 4 Issues specific to htmx version 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants