Skip to content

Commit 7509124

Browse files
authored
Apply enter and enterFrom classes in SSR for Transition component (#2059)
* apply `enter` and `enterFrom` classes in SSR This only happens on the server when `show=true` and `appear=true`. This will guarantee that the `class` is already set to the correct value before the transition happens. It worked before if you moved your classes from `enterFrom` to `className` because that prop was SSR'd. * update changelog
1 parent a0bcbae commit 7509124

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- Ensure `shift+home` and `shift+end` works as expected in the `Combobox.Input` component ([#2024](https://github.com/tailwindlabs/headlessui/pull/2024))
1616
- Improve syncing of the `Combobox.Input` value ([#2042](https://github.com/tailwindlabs/headlessui/pull/2042))
1717
- Fix crash when using `multiple` mode without `value` prop (uncontrolled) for `Listbox` and `Combobox` components ([#2058](https://github.com/tailwindlabs/headlessui/pull/2058))
18+
- Apply `enter` and `enterFrom` classes in SSR for `Transition` component ([#2059](https://github.com/tailwindlabs/headlessui/pull/2059))
1819

1920
## [1.7.4] - 2022-11-03
2021

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { useSyncRefs } from '../../hooks/use-sync-refs'
3030
import { useTransition } from '../../hooks/use-transition'
3131
import { useEvent } from '../../hooks/use-event'
3232
import { useDisposables } from '../../hooks/use-disposables'
33+
import { classNames } from '../../utils/class-names'
3334

3435
type ContainerElement = MutableRefObject<HTMLElement | null>
3536

@@ -412,6 +413,15 @@ let TransitionChild = forwardRefWithAs(function TransitionChild<
412413
let theirProps = rest
413414
let ourProps = { ref: transitionRef }
414415

416+
let isServer = typeof window === 'undefined' || typeof document === 'undefined'
417+
if (appear && show && isServer) {
418+
theirProps = {
419+
...theirProps,
420+
// Already apply the `enter` and `enterFrom` on the server if required
421+
className: classNames(rest.className, ...classes.current.enter, ...classes.current.enterFrom),
422+
}
423+
}
424+
415425
return (
416426
<NestingContext.Provider value={nesting}>
417427
<OpenClosedProvider

0 commit comments

Comments
 (0)