Repository navigation
Fix Maximum update depth exceeded due to Transition - #3782
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
RobinMalfait
force-pushed
the
fix/issue-3655
branch
from
September 2, 2025 14:22
7b82e5e to
e166008
Compare
RobinMalfait
force-pushed
the
fix/issue-3655
branch
from
September 2, 2025 22:46
40486f1 to
0391845
Compare
RobinMalfait
force-pushed
the
fix/issue-3655
branch
from
September 2, 2025 22:50
0391845 to
1a14a58
Compare
RobinMalfait
marked this pull request as ready for review
September 3, 2025 08:50
Before, when we detected that an element moved, we kept checking it against a previous position. This meant that it could toggle between `true` and `false`. With this fix, we ensure that once an element moved, it stays marked as "moved" preventing a `true`, `false`, `true`, ... loop. We do use `setState`-like calls in Render, but we ensure that the state is in a correct state before we call setState in render. This pattern is also used in the React docs: https://react.dev/reference/react/useState#storing-information-from-previous-renders
We were using values in the dependencies array that would cause new functions from being returned even though we didn't use those values inside the callback.
Instead of relying on the React lifecycle and re-renders we can make use of the state machine model outside of React. This will allow us to detect button movements as fast as possible without waiting for re-renders. I think ideally we move this new code into a nested state machine, but then we need a way to trigger state changes in parent state machines because the selectors we would rely on nested state but would also bailout because the main state didn't change. We could add the code for that _or_ switch to xstate, but in either case that would involve a lot of refactoring.
RobinMalfait
force-pushed
the
fix/issue-3655
branch
from
September 3, 2025 12:55
101176e to
5cb51f9
Compare
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
thecrypticace
approved these changes
Sep 3, 2025
This was referenced Sep 3, 2025
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) |  |  | --- ### Release Notes <details> <summary>tailwindlabs/headlessui (@​headlessui/react)</summary> ### [`v2.2.10`](https://github.com/tailwindlabs/headlessui/blob/HEAD/packages/@​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 ([#​3825](tailwindlabs/headlessui#3825)) - Fix passing props on `Fragment` error due to `Symbol(react.lazy)` ([#​3873](tailwindlabs/headlessui#3873)) ### [`v2.2.9`](https://github.com/tailwindlabs/headlessui/blob/HEAD/packages/@​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 ([#​3794](tailwindlabs/headlessui#3794)) - Don't accidentally open the `Combobox` when touching the `ComboboxButton` while dragging on mobile ([#​3795](tailwindlabs/headlessui#3795)) - Ensure sibling `Dialog` components are scrollable on mobile ([#​3796](tailwindlabs/headlessui#3796)) - Infer `Combobox` type based on `onChange` handler ([#​3798](tailwindlabs/headlessui#3798)) - Allow home/end key default behavior inside `ComboboxInput` when `Combobox` is closed ([#​3798](tailwindlabs/headlessui#3798)) - Ensure interacting with a `Dialog` on iOS works after interacting with a disallowed area ([#​3801](tailwindlabs/headlessui#3801)) - Freeze Listbox values as soon as a value is selected ([#​3802](tailwindlabs/headlessui#3802)) - Ensure refs are forwarded when freezing data ([#​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/@​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 ([#​3779](tailwindlabs/headlessui#3779)) - Ensure `onChange` types are contravariant instead of bivariant ([#​3781](tailwindlabs/headlessui#3781)) - Support `<summary>` as a focusable element inside `<details>` ([#​3389](tailwindlabs/headlessui#3389)) - Fix `Maximum update depth exceeded` crash when using `transition` prop ([#​3782](tailwindlabs/headlessui#3782)) - Ensure pressing `Tab` in the `ComboboxInput`, correctly syncs the input value ([#​3785](tailwindlabs/headlessui#3785)) - Ensure `--button-width` and `--input-width` have the latest value ([#​3786](tailwindlabs/headlessui#3786)) - Fix 'Invalid prop `data-headlessui-state` supplied to `React.Fragment`' warning ([#​3788](tailwindlabs/headlessui#3788)) - Ensure `element` in `ref` callback is always connected when rendering in a `Portal` ([#​3789](tailwindlabs/headlessui#3789)) - Ensure form state is up to date when using uncontrolled components ([#​3790](tailwindlabs/headlessui#3790)) - Ensure `data-open` on `ComboboxInput` is up to date ([#​3791](tailwindlabs/headlessui#3791)) - Ensure changing the `immediate` prop value on the `Combobox` component works as expected ([#​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
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.
This PR fixes an issue where you could run into a
Maximum update depth exceedederror in theListbox,MenuorComboboxcomponent in combination with thetransitionprop.It seems like some people ran into this, but I was never able to reproduce it. But now I figured out what the issue is, how to reproduce it and this PR should fix it as well (it at least fixes the
Maximum update depth exceededI could reproduce).To reproduce it, you don't need a lot of code, but you do need a particular setup:
This setup means that you have to scroll down to see the Listbox. When you open the Listbox, the
ListboxOptionswill be rendered increasing the height of the page. If you then close it again, the page will decrease in height again, causing the issue to happen.The next question is, why does the crash happen?
The crash happens because we are updating some internal state based on whether the
ListboxButtonmoved or not. The reason we track whether the button moved or not is to improve the UX (a bit ironic I know, because it could crashβ¦)In the Listbox component (and some others like Menu and Combobox), we track whether a button moved on the screen when you close the dropdown. If it does move, we will immediately hide the Listbox without any transitions.
This is done to improve the UX because we don't want to see a fading-out dropdown somewhere else on the screen.
Maybe it's easier if I show you an example. This example is using our UI Kit, Catalyst: https://catalyst.tailwindui.com/docs/listbox
Example 1:
Screen.Recording.2025-09-02.at.13.18.19.mov
Example 2:
Screen.Recording.2025-09-02.at.13.19.53.mov
Example 3:
Now we're going to do something very similar, but this time the next focusable element will be just outside of what is visual to the user. This will cause the browser to scroll and scroll the new element into view. We'll make the page smaller by opening devtools.
Screen.Recording.2025-09-02.at.15.03.54.mov
Example 4:
Up until now, all these make sense as a user. But here is an example of what would happen if we didn't close the dropdown immediately when the button moved.
Same steps and similar setup as Example 3, but without the special code that detects button moves.
It's going to be quick, but look near the end of this video. Once I press tab, you will see the dropdown fade out and linger around near the top of the screen.
Screen.Recording.2025-09-02.at.13.42.47.mov
(This was a little tricky to reproduce here because when you tab, the active element will be scrolled into view automatically by the browser, so the button sits in the middle of the page. But we want to make sure the dropdown button is still in the viewport~ish. This is why it's zoomed out a bit.)
Now that we established that, why did it crash in some scenarios?
The first important part is the
transitionprop. A transition allows us to keep the dropdown visible even though its internal state is "closed". This is important so that we will wait until all CSS transitions are done before actually unmounting the component.The next important part is about the extra div (
<div class="min-h-dvh" />) in the reproduction code, because it will force a scrollbar. Opening and closing the listbox will change the height of the page. This in turn will move the button up to make room for the dropdown part, therefore thebuttonwill be marked as moved.However, we keep checking whether the button moved compared to the initial position, which could result in a loop:
visiblestate (thanks to thetransition) is still set to true.To actually solve the issue, we have to make sure that once the button is marked as moved, it will stay marked as "moved" until the
enabledboolean (argument to the hook) changes again.I also did some internal refactors by moving this logic into the existing state machines instead of relying on React and when things render. I therefore also got rid of the
useDidElementMovehook entirely.Test plan
Simplified reproduction of the crash in action:
Before
Screen.Recording.2025-09-02.at.13.04.55.mov
After
Screen.Recording.2025-09-02.at.13.05.19.mov
Fixes: #3655
Fixes: #3562