motion icon indicating copy to clipboard operation
motion copied to clipboard

[BUG] AnimatePresence popLayout mode does not work within a shadow dom

Open disambiguator opened this issue 1 year ago • 6 comments

Description

If we use AnimatePresence inside a shadow DOM, the popLayout features don't work. This is because we're unable to find the temporary styles added, because shadow dom won't apply styles found in document.head.

Code sandbox repro: https://codesandbox.io/p/sandbox/framer-motion-shadow-dom-f7gkk6?file=%2Fsrc%2FApp.js%3A89%2C2

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Open the code sandbox link
  2. Click the example to run the animation. You'll notice the popLayout behavior is not occurring.
  3. Uncomment line 86, skipping the shadow DOM.
  4. popLayout starts working again.

Technical guess of the problem

From what I understand, popLayout works by applying a temporary class which positions an element as absolute during exit transition. This does not work in shadow DOMs due to the way the style is applied. I think the code here is adding the temporary class, but it's hardcoded to using document.head, which won't be available to the shadow dom.

disambiguator avatar Feb 06 '24 01:02 disambiguator

That guess at the cause seems likely :(

If anyone has a workaround for this issue, please share 🙏

cymptom avatar Sep 30 '24 22:09 cymptom

Wanted to bump this issue, currently experiencing it and would love to continue using framer motion in my project.

ParkerSm1th avatar Oct 01 '24 23:10 ParkerSm1th

Bump too. Would love any workaround!

rdamore2812 avatar Oct 01 '24 23:10 rdamore2812

I made a PR to fix this: https://github.com/framer/motion/pull/2830, works if I pass in the shadowRoot directly. Would appreciate any feedback!

tehbelinda avatar Oct 11 '24 22:10 tehbelinda

@mattgperry can you help get this merged?

dylank avatar Oct 15 '24 16:10 dylank

If anyone else needs this in the meantime, I made a tag with all the dist files included, so you can reference it directly from your package.json, i.e.

npm install 'https://gitpkg.vercel.app/tehbelinda/motion/packages/framer-motion?v11.11.10-shadow-dom' --save

(yarn add should work too but I haven't tested that one)

tehbelinda avatar Oct 29 '24 04:10 tehbelinda