You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Added .viewport modifier to x-on directive to add listeners to window.visualViewport instead - #4350
On iOS Safari (v17.3), resize events on window does not fire immediately to viewport resizes (caused by browser chrome hiding address bars). However, it does fire almost immediately when binded to window.visualViewport.
Solution
Added .viewport modifier to x-on directive to add listeners to window.visualViewport
As the user scrolls and the browser starts to hide the address bar, the resize event for window.visualViewport gets called almost immediately while the x-resize only gets called at the end of the scroll (after easing).
PR Review: #4350 — Added .viewport modifier to x-on directive
Type: Feature Verdict: Close
What's happening (plain English)
On iOS Safari (v17.3+), when the browser chrome hides/shows (e.g., the address bar slides away as you scroll), the windowresize event fires late — only after the animation completes. But window.visualViewport's resize event fires immediately as the viewport changes size.
Add a .visual-viewport modifier to the x-resize plugin — This is the better home. x-resize already handles resize observation and has a .document modifier pattern. Adding viewport support there keeps core small and puts the feature where users would naturally look for it.
Users can already do x-on:resize.window — For many cases, the slight delay on iOS is acceptable. The PR solves a real but narrow iOS-specific timing issue.
A custom Alpine plugin — This is roughly 5 lines of code as a userland plugin. Given the narrow use case, that's probably the right level of abstraction.
The .viewport modifier test correctly fails without the fix and passes with it
No CI checks configured on this branch
Code Review
Issues found:
Naming inconsistency — PR title says .viewport, test is named .viewport modifier, but the actual modifier in code is .visual. Pick one name and be consistent.
Missing key modifier exclusion (on.js:131) — 'visual' is not in the exclusion list inside isListeningForASpecificKeyThatHasntBeenPressed. The existing modifiers window and document are both excluded there. Without this, using .visual on a keydown event would break key filtering.
No null guard — window.visualViewport can be null in non-visual contexts (workers, some test environments). The code would throw when trying to call addEventListener on null.
No docs — Feature needs documentation alongside .window and .document in the modifier docs.
Test name vs modifier mismatch — Test says .viewport modifier but tests .visual. The viewport destructured from the test callback is Cypress's cy.viewport() helper, not related to this feature — adds to the confusion.
Security
No security concerns identified.
Verdict
Recommend closing. Here's why:
This belongs in x-resize, not core.window.visualViewport only emits resize and scroll events. A generic listener-target modifier in core x-on implies it works for any event — misleading. The x-resize plugin already handles resize listening and is the natural home for viewport-aware resize detection.
Zero community demand. No reactions on the PR or linked issues. The bar for new core API surface should be high.
Narrow use case. This solves an iOS Safari timing issue for viewport resize. It's the kind of thing a 5-line userland plugin handles perfectly.
Implementation has bugs. Missing key modifier exclusion, no null guard, naming inconsistency between title/test/code.
If the iOS visualViewport timing issue is important enough to address, I'd suggest the contributor open a PR against the x-resize plugin instead, adding something like x-resize.viewport that uses visualViewport.addEventListener('resize', ...) under the hood.
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
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.
Problem
On iOS Safari (v17.3),
resizeevents onwindowdoes not fire immediately to viewport resizes (caused by browser chrome hiding address bars). However, it does fire almost immediately when binded towindow.visualViewport.Solution
Added
.viewportmodifier tox-ondirective to add listeners towindow.visualViewport