Repository navigation
fix: make scrollTarget:window and showTarget:window scroll the page - #4159
Merged
1cg merged 1 commit intoNov 1, 2026
Merged
Conversation
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
hx-swap="scroll:top scrollTarget:window"andhx-swap="show:top showTarget:window"don't scroll the page.__findExtresolves thewindowextended selector to thewindowobject, which has noscrollTopand noscrollIntoView. So in the scroll case__handleScrollsets a property that has no effect, and in the show case thescrollIntoView?.()call is silently skipped.htmx 4 suggests this form as the replacement for the old
show:window:top/scroll:window:topsyntax, and the upgrade checker rewritesshow:window:toptoshow:top showTarget:window. As a result, upgraded pages lose their scroll-to-top behaviour.This change maps
windowtodocument.scrollingElementfor bothscrollTargetandshowTarget. It also updates the hx-swap reference: its "Scroll the window" example still used the removedscroll:window:topform, which now parses asscroll: "window:top"and does nothing.Scroll down and click: before this change the page stays where it is, after it the page scrolls back to the top.
Corresponding issue: related to #3544
Testing
I added two tests to
test/tests/attributes/hx-swap.js:scroll:top scrollTarget:windowscrolls the page back to the top. Without the fix it fails withexpected 1016 to equal +0.show:bottom showTarget:windowscrolls the page down. Without the fix it fails withexpected +0 to be above +0.Both pass with the fix. I ran the full suite in Chrome with
web-test-runner --config test/web-test-runner.config.mjsandCHROME_PATHset (--concurrency 1): 1777 passed, 0 failed, 3 skipped. I couldn't usenpm run testbecause the Playwright browser build it expects isn't installed on this machine.Checklist
masterfor website changes,devforsource changes)
approved via an issue
npm run test) and verified that it succeeded