improve hx-head title and event handling - #4092
Open
MichaelWest22 wants to merge 5 commits into
Open
MichaelWest22 wants to merge 5 commits into
MichaelWest22 wants to merge 5 commits into
Conversation
MichaelWest22
force-pushed
the
hx-head-append2
branch
from
September 21, 2026 14:38
13d79af to
f16ece2
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Collaborator
Author
|
updated those |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded