Skip to content

Commit 5667e84

Browse files
authored
Fix "blank" screen on initial load of Transition component (#1823)
* use a "cancellable" microTask * update changelog
1 parent 0954ec5 commit 5667e84

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4040
- Expose the `value` from the `Combobox` and `Listbox` components render prop ([#1822](https://github.com/tailwindlabs/headlessui/pull/1822))
4141
- Improve `scroll lock` on iOS ([#1824](https://github.com/tailwindlabs/headlessui/pull/1824))
4242
- Fix maximum call stack size exceeded error on `Tab` component when using `as={Fragment}` ([#1826](https://github.com/tailwindlabs/headlessui/pull/1826))
43+
- Fix "blank" screen on initial load of `Transition` component ([#1823](https://github.com/tailwindlabs/headlessui/pull/1823))
4344

4445
## [1.6.6] - 2022-07-07
4546

packages/@headlessui-react/src/components/transitions/transition.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import {
2222
} from '../../utils/render'
2323
import { OpenClosedProvider, State, useOpenClosed } from '../../internal/open-closed'
2424
import { match } from '../../utils/match'
25-
import { microTask } from '../../utils/micro-task'
2625
import { useIsMounted } from '../../hooks/use-is-mounted'
2726
import { useIsoMorphicEffect } from '../../hooks/use-iso-morphic-effect'
2827
import { useLatestValue } from '../../hooks/use-latest-value'
2928
import { useServerHandoffComplete } from '../../hooks/use-server-handoff-complete'
3029
import { useSyncRefs } from '../../hooks/use-sync-refs'
3130
import { useTransition } from '../../hooks/use-transition'
3231
import { useEvent } from '../../hooks/use-event'
32+
import { useDisposables } from '../../hooks/use-disposables'
3333

3434
type ContainerElement = MutableRefObject<HTMLElement | null>
3535

@@ -128,6 +128,7 @@ function useNesting(done?: () => void, parent?: NestingContextValues) {
128128
let doneRef = useLatestValue(done)
129129
let transitionableChildren = useRef<NestingContextValues['children']['current']>([])
130130
let mounted = useIsMounted()
131+
let d = useDisposables()
131132

132133
let unregister = useEvent((container: ContainerElement, strategy = RenderStrategy.Hidden) => {
133134
let idx = transitionableChildren.current.findIndex(({ el }) => el === container)
@@ -142,7 +143,7 @@ function useNesting(done?: () => void, parent?: NestingContextValues) {
142143
},
143144
})
144145

145-
microTask(() => {
146+
d.microTask(() => {
146147
if (!hasChildren(transitionableChildren) && mounted.current) {
147148
doneRef.current?.()
148149
}

packages/@headlessui-react/src/utils/disposables.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { microTask } from './micro-task'
2+
13
export function disposables() {
24
let disposables: Function[] = []
35
let queue: Function[] = []
@@ -33,6 +35,18 @@ export function disposables() {
3335
return api.add(() => clearTimeout(timer))
3436
},
3537

38+
microTask(...args: Parameters<typeof microTask>) {
39+
let task = { current: true }
40+
microTask(() => {
41+
if (task.current) {
42+
args[0]()
43+
}
44+
})
45+
return api.add(() => {
46+
task.current = false
47+
})
48+
},
49+
3650
add(cb: () => void) {
3751
disposables.push(cb)
3852
return () => {

0 commit comments

Comments
 (0)