Skip to content

improve hx-head title and event handling - #4092

Open
MichaelWest22 wants to merge 5 commits into
bigskysoftware:four-devfrom
MichaelWest22:hx-head-append2
Open

MichaelWest22 wants to merge 5 commits into
bigskysoftware:four-devfrom
MichaelWest22:hx-head-append2

Conversation

@MichaelWest22

@MichaelWest22 MichaelWest22 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Description

Title is a singleton and does not need the same append behavior like the other head attributes.
hx-head extension can right now append duplicate titles so instead of trying to handle title in hx-head we can just skip over title handling and allow core htmx title handling to happen naturally. The only exception is we still need to handle removing of title in merge mode that core does not do. This also lets ignoreTitle swap modifier work if used naturally.

Note that ignoreTitle impacts if it should not update the title in swap but it does not impact hx-heads default behavior of removing missing head elements in full body merge mode but it is not a realistic need to use ignoreTitle to replace the whole body and head with merge head mode and expect ignoreTitle to preserve the old title when hx-head is trying to make the head match the new page state. So I have not tried to make ignoreTitle somehow preserve the existing title in head.

Also have added a new htmx.config.head.clearTitle config which defualts to false but if set true can control the way title is cleared. In full body merge mode we remove any head records like title if it was missing on the new page. During append style partial page updates the existing title is not removed as you are only partially updating the head with additions. But there could be cases where you are doing partial page replacement with append and expect the new page to have no title so I've added this clearTitle config that if set make append mode clear the title if not set as well.

Also it was reported that hx-head fires duplicate events for remove which I have also resolved

Corresponding issue:
#4070
#4088

Testing

Added tests

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

@scrhartley

This comment was marked as resolved.

@scrhartley

This comment was marked as resolved.

@MichaelWest22

Copy link
Copy Markdown
Collaborator Author

updated those

@scrhartley

scrhartley commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

I've added one last comment to issue #4070, so you can decide if you want to handle it in this PR or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants