question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working with AnimatePresence in 2.0

See original GitHub issue

Based on the example from the release notes:

function New() {
  const [ isOpen, setOpen ] = React.useState( false )

  const { layerProps, triggerProps, renderLayer } = useLayer({ isOpen })

  return (
    <AnimatePresence>
      <button onClick={() => setOpen( !isOpen )} {...triggerProps}>Trigger</button>
      {isOpen && renderLayer( <motion.div {...layerProps}>Layer</motion.div> )}
    </AnimatePresence>
  )
}

This triggers the following error:

Uncaught Error: react-laag: Could not find a valid reference for the layer element. There might be 2 causes:
   - Make sure that the 'ref' is set correctly on the layer element when isOpen: true. Also make sure your component forwards the ref with "forwardRef()".
   - Make sure that you are actually rendering the layer when the isOpen prop is set to true

It does work when I replace the <AnimatePresence> with a Fragment (<>).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rijkcommented, Dec 16, 2020

Ok, so my bad, I changed the implementation and it’s working fine. Thanks!

1reaction
everweijcommented, Dec 16, 2020

That is a valid concern, but I think this will not be so bad. v2 has a lazy strategy regarding monitoring positioning, meaning that only layers that are open are affected. Also I did some perf-measuring in a production setting (node.env === ‘production’ / without animations though). On a macbook pro (2017) calculating a single position for 1 layer takes ~ less than 0.1ms. In other words, it can take quite a lot. Haven’t tested it with lots of animations though. Will put this on my todo-list to pick up somewhere this week 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Animate Presence exit not working framer motion
The reason that this is not working is that you have to explicitly specify the key of the child that you are conditionally...
Read more >
framer-motion animate presence unmount - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >
Chakra UI + Framer Motion
Chakra UI + Framer Motion. This example shows how to add some interesting motion interaction or animation to your Chakra UI websites or...
Read more >
Page Transitions with Gatsby + Framer Motion - Janessa Garrow
Some knowledge of Framer Motion is also helpful, but not necessary. ... Using AnimatePresence allows us to give a motion component an exit ......
Read more >
framer-motion | Yarn - Package Manager
Fixing AnimatePresence children not re-rendering when their exiting siblings ... Fixed unit type conversion not working with previously-undefined values.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found