Skip to content

Ensure sibling Dialog components are scrollable on mobile - #3796

Merged
RobinMalfait merged 4 commits into
mainfrom
fix/issue-3378
Sep 17, 2025
Merged

RobinMalfait merged 4 commits into
mainfrom
fix/issue-3378

Conversation

@RobinMalfait

Copy link
Copy Markdown
Collaborator

This PR fixes an issue where opening a sibling dialog doesn't allow you to scroll the second (top most) dialog on iOS anymore.

The issue here is that on iOS we have to do a lot of annoying work to make the dialog behave like a dialog and prevent scrolling outside of the dialog.

To make this all work, we PUSH and POP some information to know what the top-most dialog is. The moment there is 1 open dialog, and as long as there is 1 dialog we scroll lock the page, the moment there are 0 dialogs again we unlock the page again.

Each dialog also has a set of "allowed containers", these are just container DOM nodes where we allow scrolling.

But the issue is that we were dealing with stale data. These are the events you see when we open dialogs:

[Log] Open dialog #1
[Log] PUSH
[Log] SCROLL_PREVENT  β†’ We start preventing scroll because there is 1 dialog
[Log] Open dialog #2
[Log] PUSH            β†’ We opened a second dialog, but the `SCROLL_PREVENT`
                      β†’ was already active and doesn't re-evaluate
[Log] POP             β†’ POP from dialog #1 because not the top-most anymore

Any time we PUSH we also track new meta data with the allowed containers. But
we were already preventing scroll, so we had stale meta data.

To solve this, I can think of 2 solutions:

  1. The moment we POP, we also SCROLL_ALLOW again, but realize that we still have 1 dialog open, so we SCROLL_PREVENT again. This just feels wrong to me though.
  2. Any time we PUSH / POP, we re-evaluate the meta data, and when receive the meta data in the SCROLL_PREVENT event listeners, we call the function to get the latest meta data not the old stale data.

Test plan

In both scenario's I first open the dialog, then scroll.

before:

ScreenRecording_09-17-2025.17-18-13_1.MP4

after:

ScreenRecording_09-17-2025.17-18-35_1.MP4

Fixes: #3378

This is just a very very small optimization, but wanted to optimize it
since I noticed it.

Essentially `containers.flatMap(resolve => resolve())` is a bit wasteful
if we you have `n` containers, but you already found a match in the
  first container.

  If that's the case, then we resolved `n-1` containers for nothing.
  Depending on what we actually do during this resolve step it could be
  a lot of unnecessary work (e.g.: querying the DOM).
Otherwise we have to build it on every scroll event and that would be
very expensive.
@vercel

vercel Bot commented Sep 17, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
headlessui-react Ready Ready Preview Comment Sep 17, 2025 3:22pm
headlessui-vue Ready Ready Preview Comment Sep 17, 2025 3:22pm

Comment on lines +77 to +79
meta() {
return entry.computedMeta
},

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered making this a getter, but then you have to use entry.meta instead of destructuring it to prevent the meta to be evaluated already.

// that happens later can update the meta information. Otherwise we would
// use stale meta information.
meta() {
return entry.computedMeta

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used entry instead of destructuring the computedMeta to ensure we are looking at the latest data. Alternatively we could use this.get(doc).computedMeta or something

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine πŸ€·β€β™‚οΈ

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this kind of sounds like the opposite of the above message, but the difference is a getter here vs destructuring in another spot so the connection might not be as clear.

@RobinMalfait
RobinMalfait merged commit b0615ad into main Sep 17, 2025
@RobinMalfait
RobinMalfait deleted the fix/issue-3378 branch September 17, 2025 15:33
cesmarvin pushed a commit to scm-manager/scm-manager that referenced this pull request Nov 6, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [@headlessui/react](https://github.com/tailwindlabs/headlessui) ([source](https://github.com/tailwindlabs/headlessui/tree/HEAD/packages/@headlessui-react)) | [`2.2.7` β†’ `2.2.10`](https://renovatebot.com/diffs/npm/@headlessui%2freact/2.2.7/2.2.10) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@headlessui%2freact/2.2.10?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@headlessui%2freact/2.2.7/2.2.10?slim=true) |

---

### Release Notes

<details>
<summary>tailwindlabs/headlessui (@&#8203;headlessui/react)</summary>

### [`v2.2.10`](https://github.com/tailwindlabs/headlessui/blob/HEAD/packages/@&#8203;headlessui-react/CHANGELOG.md#2210---2026-04-07)

[Compare Source](https://github.com/tailwindlabs/headlessui/compare/@headlessui/react@v2.2.9...@headlessui/react@v2.2.10)

##### Fixed

- Don’t render `<Portal>` while hydrating ([#&#8203;3825](tailwindlabs/headlessui#3825))
- Fix passing props on `Fragment` error due to `Symbol(react.lazy)` ([#&#8203;3873](tailwindlabs/headlessui#3873))

### [`v2.2.9`](https://github.com/tailwindlabs/headlessui/blob/HEAD/packages/@&#8203;headlessui-react/CHANGELOG.md#229---2025-09-25)

[Compare Source](https://github.com/tailwindlabs/headlessui/compare/@headlessui/react@v2.2.8...@headlessui/react@v2.2.9)

##### Fixed

- Improve focus management in shadow DOM roots ([#&#8203;3794](tailwindlabs/headlessui#3794))
- Don't accidentally open the `Combobox` when touching the `ComboboxButton` while dragging on mobile ([#&#8203;3795](tailwindlabs/headlessui#3795))
- Ensure sibling `Dialog` components are scrollable on mobile ([#&#8203;3796](tailwindlabs/headlessui#3796))
- Infer `Combobox` type based on `onChange` handler ([#&#8203;3798](tailwindlabs/headlessui#3798))
- Allow home/end key default behavior inside `ComboboxInput` when `Combobox` is closed ([#&#8203;3798](tailwindlabs/headlessui#3798))
- Ensure interacting with a `Dialog` on iOS works after interacting with a disallowed area ([#&#8203;3801](tailwindlabs/headlessui#3801))
- Freeze Listbox values as soon as a value is selected ([#&#8203;3802](tailwindlabs/headlessui#3802))
- Ensure refs are forwarded when freezing data ([#&#8203;3390](tailwindlabs/headlessui#3390))
- Do not serialize React components into form fields ([49e9e8e](tailwindlabs/headlessui@49e9e8e))

### [`v2.2.8`](https://github.com/tailwindlabs/headlessui/blob/HEAD/packages/@&#8203;headlessui-react/CHANGELOG.md#228---2025-09-12)

[Compare Source](https://github.com/tailwindlabs/headlessui/compare/@headlessui/react@v2.2.7...@headlessui/react@v2.2.8)

##### Fixed

- Ensure we are not freezing data when the `static` prop is used ([#&#8203;3779](tailwindlabs/headlessui#3779))
- Ensure `onChange` types are contravariant instead of bivariant ([#&#8203;3781](tailwindlabs/headlessui#3781))
- Support `<summary>` as a focusable element inside `<details>` ([#&#8203;3389](tailwindlabs/headlessui#3389))
- Fix `Maximum update depth exceeded` crash when using `transition` prop ([#&#8203;3782](tailwindlabs/headlessui#3782))
- Ensure pressing `Tab` in the `ComboboxInput`, correctly syncs the input value ([#&#8203;3785](tailwindlabs/headlessui#3785))
- Ensure `--button-width` and `--input-width` have the latest value ([#&#8203;3786](tailwindlabs/headlessui#3786))
- Fix 'Invalid prop `data-headlessui-state` supplied to `React.Fragment`' warning ([#&#8203;3788](tailwindlabs/headlessui#3788))
- Ensure `element` in `ref` callback is always connected when rendering in a `Portal` ([#&#8203;3789](tailwindlabs/headlessui#3789))
- Ensure form state is up to date when using uncontrolled components ([#&#8203;3790](tailwindlabs/headlessui#3790))
- Ensure `data-open` on `ComboboxInput` is up to date ([#&#8203;3791](tailwindlabs/headlessui#3791))
- Ensure changing the `immediate` prop value on the `Combobox` component works as expected ([#&#8203;3792](tailwindlabs/headlessui#3792))

</details>

---

### Configuration

πŸ“… **Schedule**: (in timezone Europe/Berlin)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

β™» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

πŸ”• **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMy4xIiwidXBkYXRlZEluVmVyIjoiNDQuMTMuMSIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOltdfQ==-->

This branch was successfully deployed

2 active deployments
Preview – headlessui-react β€” 07be1ac9 Deployed Sep 17, 2025 by vercel[bot]
Preview – headlessui-vue β€” 07be1ac9 Deployed Sep 17, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sibling Dialogs can't touch-scroll on mobile

2 participants