Skip to content

Commit

Permalink
fix(DialogBase): Don't trigger the hide animation on strict mode (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriqueLimas authored Nov 4, 2024
1 parent 40186b7 commit d201e5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .storybook/preview.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, {StrictMode} from 'react'
import { EbaySvg } from '../src/ebay-svg'

import "@ebay/skin"
Expand All @@ -8,10 +8,10 @@ import "@ebay/skin/marketsans"
export default {
decorators: [
Story => (
<>
<StrictMode>
<EbaySvg/>
<Story/>
</>
</StrictMode>
)
],
parameters: {
Expand Down
8 changes: 5 additions & 3 deletions src/ebay-dialog-base/components/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function useDialogAnimation({
enabled,
onTransitionEnd
}: DialogAnimationHookProps): void {
const firstRender = useRef(true)
const previousOpenValue = useRef(open)

useLayoutEffect(() => {
if (!enabled) {
Expand All @@ -54,7 +54,9 @@ export function useDialogAnimation({
classPrefix,
onTransitionEnd
})
} else if (!firstRender.current) {
// Trigger the hide animation only when that "open" value changed to make sure it doesn't flicker the dialog.
// The error was visible in StrictMode where the component renders twice.
} else if (previousOpenValue.current !== open) {
cancelCurrentAnimation = hideAnimation({
dialog: dialogRef,
waitFor: transitionElements,
Expand All @@ -63,7 +65,7 @@ export function useDialogAnimation({
})
}

firstRender.current = false
previousOpenValue.current = open

return () => {
if (cancelCurrentAnimation) {
Expand Down

0 comments on commit d201e5e

Please sign in to comment.