Skip to content
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

[BUG] layoutId and AnimatePresence together fail to unmount content #2172

Closed
onnlucky opened this issue Jun 2, 2023 · 1 comment · Fixed by #2220
Closed

[BUG] layoutId and AnimatePresence together fail to unmount content #2172

onnlucky opened this issue Jun 2, 2023 · 1 comment · Fixed by #2220
Assignees
Labels
bug Something isn't working
Milestone

Comments

@onnlucky
Copy link

onnlucky commented Jun 2, 2023

import * as React from "react";
import { createRoot } from "react-dom/client";
import { AnimatePresence, motion } from "framer-motion";

const rootElement = document.getElementById("root");
const root = createRoot(rootElement);

const animation = {
  x: 0, // Comment this out and it works.
  opacity: 0.5
};

export const Screen = function Component() {
  const [visible, setVisible] = React.useState(false);
  return (
    <>
      <motion.div
        className={"button"}
        onTap={() => setVisible(!visible)}
        style={{ width: 100, height: 100, background: "green" }}
      />
      <AnimatePresence>
        {visible && (
          <motion.div
            layoutId={"An2J7Niah"} // Comment this out and it works.
            style={{ width: 100, height: 100, background: "blue" }}
            className={"BLUE"}
            exit={animation}
          />
        )}
      </AnimatePresence>
    </>
  );
};

root.render(<Screen />);

With the above code (code sandbox: https://codesandbox.io/s/aged-leaf-1tlyr2?file=/src/index.tsx ), click the green square, will show a blue square, click it again, it should disappear after an exit animation. But instead it will never go away.

This is a regression in 10.12.8. And one way to fix it is to change create-projection-node.ts use of the queueMicrotask, like this:

        didUpdate() {
            if (!this.updateScheduled) {
                this.updateScheduled = true
                // queueMicrotask(() => this.update())
                this.update()
            }
        }
@onnlucky onnlucky added the bug Something isn't working label Jun 2, 2023
@onnlucky
Copy link
Author

onnlucky commented Jun 2, 2023

This seems related to: #2145 and #2110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants