docs: clarify HX-Retarget interaction with hx-swap="none" (#3446)#3771
Open
manwithacat wants to merge 1 commit intobigskysoftware:masterfrom
Open
docs: clarify HX-Retarget interaction with hx-swap="none" (#3446)#3771manwithacat wants to merge 1 commit intobigskysoftware:masterfrom
manwithacat wants to merge 1 commit intobigskysoftware:masterfrom
Conversation
…ware#3446) HX-Retarget only changes *where* the swap happens — the swap style is still determined by the source element's hx-swap (or by HX-Reswap). When the source uses hx-swap="none", retargeting alone produces a no-op because the "none" swap style applies at the new target too. Updates the HX-Retarget entries in both docs.md and reference.md to spell this out and point users at HX-Reswap. The behavior itself is intentional and consistent — only the docs were silent on this combination. The original issue reporter noticed the surprise and explicitly suggested "I would update the docs to include that setting hx-swap='none' will prevent the use of a swap via HX-Retarget." Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Fixes #3446.
Background
The issue reporter set
hx-swap="none"on a form, then expected anHX-Retargetresponse header to cause a swap to happen at the new target. Tracing the code (src/htmx.js:4848–4929):responseHandling.swapistruefor the 2xx response, so the swap block is entered.HX-RetargetupdatesresponseInfo.targetto the new selector.getSwapSpecification(elt, swapOverride)readshx-swap="none"from the source element.swapWithStyle('none', ...)returns immediately — no DOM change at the new target.This is intentional and consistent:
HX-Retargetis a "where" header, not a "whether" header. Thenoneswap style applies at the new target just as it would have at the original. The reporter even noted in their suggestion: "If this is the expected behavior, I would update the docs to include that setting hx-swap='none' will prevent the use of a swap via HX-Retarget."The fix
This PR is exactly that doc update. Two single-line edits in the response-headers tables:
www/content/docs.md— adds a clarifying sentence to theHX-Retargetentry, pointing users atHX-Reswapfor the "swap was 'none', but I want to swap at the new target" case.www/content/reference.md— same clarification, parenthetical form to match the table style.Docs-only, no code change. Targeting
masterper CONTRIBUTING.md.What I'm not changing, and why
The behavior itself isn't a bug. Making
HX-Retargetimplicitly overridehx-swap="none"would be a backwards-incompatible change to a header whose contract is well understood by the wider htmx ecosystem (extensions, frameworks, server libraries). Any user who genuinely wants the source's swap style overridden already has the right tool:HX-Reswap.