motion icon indicating copy to clipboard operation
motion copied to clipboard

[BUG] AnimatePresence cannot be used as a JSX component

Open RicBruIAI opened this issue 1 year ago • 11 comments

Describe the bug

Since today I am keeping this error related to AnimatePresence, yesterday was working well.

Provide a CodeSandbox reproduction of the bug

ERROR in src/pages/..../MyPage.tsx:33:10
TS2786: 'AnimatePresence' cannot be used as a JSX component.
  Its return type 'Element | undefined' is not a valid JSX element.
    31 |     <div className={styles.BodyContainer}>
    32 |       <Accordion onToggle={handleToggle} openItems={openItems} multiple collapsible>
  > 33 |         <AnimatePresence>
       |          ^^^^^^^^^^^^^^^
    34 |           {appGroups?.map((group: IGroup, index: number) => (
    35 |             <Group
    36 |               key={group.motionId}

Steps to reproduce

NodeJS version: 16.20.0

React versions: "@types/react": "^18.2.6", "@types/react-dom": "^18.2.4"

Just run: npm start

Expected behavior

Justo keep working

RicBruIAI avatar Jan 24 '25 15:01 RicBruIAI

[I think it's this line: (https://github.com/motiondivision/motion/blob/a7926e2a41a1c1f76895db848ecc2ab8446a4458/packages/framer-motion/src/components/AnimatePresence/index.tsx#L149)

If you replace:

        /**
         * Early return to ensure once we've set state with the latest diffed
         * children, we can immediately re-render.
         */
        return

with

        /**
         * Early return to ensure once we've set state with the latest diffed
         * children, we can immediately re-render.
         */
        return <></>;

The return type should change to just JSX.Element

robert-j-webb avatar Jan 24 '25 17:01 robert-j-webb

Same issue

Maxssobolev avatar Jan 28 '25 09:01 Maxssobolev

same issue

musab-olurode avatar Jan 30 '25 13:01 musab-olurode

Yep I got the same issue

TristanKwant avatar Jan 30 '25 14:01 TristanKwant

Will take a look tomorrow!

mattgperry avatar Jan 30 '25 15:01 mattgperry

I had this error on react 18, upgrade to react 19 if possible, will go away

ImExoOdeex avatar Jan 30 '25 17:01 ImExoOdeex

Can you try 12.0.8-alpha.0 to see if this fixes it for you?

mattgperry avatar Jan 31 '25 15:01 mattgperry

Can you try 12.0.8-alpha.0 to see if this fixes it for you?

Ok I'll give it a try!

RicBruIAI avatar Jan 31 '25 15:01 RicBruIAI

How was it @RicBruIAI ?

mattgperry avatar Feb 02 '25 08:02 mattgperry

How was it @RicBruIAI ?

I tried it, and it worked! Just remember to delete node_modules + lock file and reinstall dependencies.

Thanks for the fix @mattgperry 👍🏾 Hope it works for others too.

Graquick avatar Feb 02 '25 21:02 Graquick

It is working! thank you all!

RicBruIAI avatar Feb 03 '25 09:02 RicBruIAI