Skip to content

Comments

Fix morph error with empty id attributes#3639

Merged
MichaelWest22 merged 1 commit intobigskysoftware:fourfrom
scriptogre:fix/morph-empty-id
Jan 29, 2026
Merged

Fix morph error with empty id attributes#3639
MichaelWest22 merged 1 commit intobigskysoftware:fourfrom
scriptogre:fix/morph-empty-id

Conversation

@scriptogre
Copy link
Collaborator

@scriptogre scriptogre commented Jan 29, 2026

Summary

  • Skip elements with id="" when building the persistent ID set during morphing

Problem

When both old and new content have elements like <h1 id="">, the empty string was being treated as a valid persistent ID. This caused HierarchyRequestError when sibling elements differed between pages (e.g. <section> vs <div>).

Minimal reproduction

Page A:

<body hx-boost:inherited="true" hx-swap:inherited="innerMorph">
  <h1 id="">A</h1>
  <section>X</section>
  <a href="/b">Go to B</a>
</body>

Page B:

<body hx-boost:inherited="true" hx-swap:inherited="innerMorph">
  <h1 id="">B</h1>
  <div>Y</div>
  <a href="/a">Go to A</a>
</body>

Navigating from A to B throws:

HierarchyRequestError: Failed to execute 'insertBefore' on 'Node': The new child element contains the parent.

Test plan

  • Added test case for empty id handling
  • All existing morph tests pass

@scriptogre scriptogre changed the title skip empty id attributes in morph persistent ID matching fix morph error with empty id attributes Jan 29, 2026
@scriptogre scriptogre changed the title fix morph error with empty id attributes Fix morph error with empty id attributes Jan 29, 2026
@MichaelWest22 MichaelWest22 added the htmx 4 Issues specific to htmx version 4 label Jan 29, 2026
@MichaelWest22 MichaelWest22 merged commit 18a05bc into bigskysoftware:four Jan 29, 2026
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.

2 participants