Skip to content

perf(ui): do not re-animate drawer on re-render, reduce useEffects #12743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/ui/src/elements/Drawer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'
import { Modal, useModal } from '@faceless-ui/modal'
import React, { createContext, use, useCallback, useEffect, useState } from 'react'
import React, { createContext, use, useCallback, useLayoutEffect, useState } from 'react'

import type { Props, TogglerProps } from './types.js'

Expand Down Expand Up @@ -58,14 +58,11 @@ export const Drawer: React.FC<Props> = ({
const { closeModal, modalState } = useModal()
const drawerDepth = useDrawerDepth()

const [isOpen, setIsOpen] = useState(false)
const [animateIn, setAnimateIn] = useState(false)
const isOpen = !!modalState[slug]?.isOpen

useEffect(() => {
setIsOpen(modalState[slug]?.isOpen)
}, [slug, modalState])
const [animateIn, setAnimateIn] = useState(isOpen)

useEffect(() => {
useLayoutEffect(() => {
setAnimateIn(isOpen)
}, [isOpen])

Expand Down
Loading