Repository navigation
Fix: document title no longer updated for responses suppressed by noSwap - #4118
Open
alizamani1616 wants to merge 1 commit into
Open
alizamani1616 wants to merge 1 commit into
alizamani1616 wants to merge 1 commit into
Conversation
When a response status matches htmx.config.noSwap (e.g. the default [204, 304], or '4xx'/'5xx' pushed by the htmx-2-compat extension), content swapping is correctly skipped but a <title> in the response body still updated document.title. htmx 2 never touched the title for non-swapped responses, and noSwap exists to restore that behavior. __handleStatusCodes now sets ctx.noSwap = true alongside ctx.swap = 'none', and swap() skips the title update when it is set. Explicit hx-swap='none' and hx-status:*='swap:none' keep updating the title, matching htmx 2. Fixes bigskysoftware#4113
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
When a response status matches
htmx.config.noSwap— the default[204, 304], or"4xx"/"5xx"pushed by thehtmx-2-compatextension — htmx correctly skips swapping the response content, but if the response body contained a<title>, the document title was still updated:A
404/500response with<title>Error</title>in the body silently changed the page title even though nothing was swapped.htmx 2 never touched the title for a response that was not swapped, and
noSwapis the documented way to restore htmx 2 behavior, so it should not update the title either.Fixes #4113
Root cause
__handleStatusCodesmarks the response as non-swappable by settingctx.swap = "none", andswap()still runs (events, indicators, OOB handling). The title update at the end ofswap()only checkedignoreTitle, so thenoneswap style coming fromnoSwapstill updateddocument.title.Fix
__handleStatusCodessetsctx.noSwap = truealongsidectx.swap = "none"when the status matches thenoSwapconfig.swap()skips the title update whenctx.noSwapis set.Explicit
hx-swap="none"andhx-status:*="swap:none"overrides still update the title, matching htmx 2 behavior, since they represent a deliberate swap specification rather than status-based suppression.Testing
noSwapflag intest/tests/unit/__handleStatusCodes.js(set for exact and wildcard patterns, not set for swappable statuses orhx-statusoverrides).test/tests/unit/swap.js: no title update withnoSwap: true, title still updates for plainswap: "none"without the flag.noSwap: ["4xx","5xx"], a404response containing<title>Error</title>no longer changesdocument.title; before the fix it changed it to "Error" while the content stayed unswapped, exactly as reported.Full suite passes: 1742 tests, 0 failures, 100% coverage of
src/htmx.js.