react-responsive-modal icon indicating copy to clipboard operation
react-responsive-modal copied to clipboard

Screen Glitch When Close Modal

Open ardyanrizki opened this issue 2 years ago • 15 comments

Bug report

Describe the bug

When closing the modal an unexpected page glitch/blinking screen occurs. The modal still could close completely after that.

To Reproduce

Take action to close the modal either by clicking modal's close button, ESC, or custom button inside modal that calls the close function.

Expected behavior

Modal closes smoothly without any odd blinks.

Screenshots

https://user-images.githubusercontent.com/70071272/167860371-0cde704d-3f27-40d4-bd14-d4d1be77c3c4.mov

System information

  • Version of react-responsive-modal: ^6.2.0
  • Version of react: 18.1.0
  • Version of next: 12.1.6
  • Version of react-dom": 18.1.0
  • Browser version: Chrome 101.0.4951.54 (Official Build) (arm64), Safari 15.4 (17613.1.17.1.13)

Additional context

This case happens on my web page here. You can clicking the kebab menu (three dots icon) at the top right page to show the modal and then click "Cancel" to close it.

ardyanrizki avatar May 11 '22 13:05 ardyanrizki

Temporary fix ( mount|unmount ) modal

{
       open && <Modal />
}
import "./styles.css";

import "react-responsive-modal/styles.css";
import { Modal } from "react-responsive-modal";
import { useState } from "react";

export default function App() {
  const [open, setOpen] = useState(false);

  const onOpenModal = () => setOpen(true);
  const onCloseModal = () => setOpen(false);

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <button onClick={onOpenModal}>Open</button>
      {open && (
        <Modal open={open} onClose={onCloseModal} center>
          <h2>Simple centered modal</h2>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
            pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet
            hendrerit risus, sed porttitor quam.
          </p>
        </Modal>
      )}
    </div>
  );
}

omkhetwal avatar May 11 '22 14:05 omkhetwal

Temporary fix ( mount|unmount ) modal

{
       open && <Modal />
}
import "./styles.css";

import "react-responsive-modal/styles.css";
import { Modal } from "react-responsive-modal";
import { useState } from "react";

export default function App() {
  const [open, setOpen] = useState(false);

  const onOpenModal = () => setOpen(true);
  const onCloseModal = () => setOpen(false);

  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <button onClick={onOpenModal}>Open</button>
      {open && (
        <Modal open={open} onClose={onCloseModal} center>
          <h2>Simple centered modal</h2>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
            pulvinar risus non risus hendrerit venenatis. Pellentesque sit amet
            hendrerit risus, sed porttitor quam.
          </p>
        </Modal>
      )}
    </div>
  );
}

Thank you for your workaround @omkhetwal. Does this happen often in any case?

ardyanrizki avatar May 12 '22 04:05 ardyanrizki

@ardyanrizki I'm not sure, there were more than 4 instances where I had to use Modal in the application, at some place I noticed there wasn't any glitch, then I checked the difference so when I came across your issue, I did the change and worked for me too. It didn't happen in previous versions of the library though.

omkhetwal avatar May 12 '22 04:05 omkhetwal

I have the same issue (with same versions), any updates on this?

huksley avatar Jun 13 '22 12:06 huksley

Same issue here

antosvle avatar Jun 28 '22 10:06 antosvle

+1

mazzomix avatar Jul 01 '22 09:07 mazzomix

I blame this on React 18. Started happening to me after upgrading to React 18

laurenskling avatar Jul 01 '22 10:07 laurenskling

Same for me

Maciej916 avatar Jul 04 '22 20:07 Maciej916

Some investigations here https://github.com/radix-ui/primitives/pull/1344

huksley avatar Jul 05 '22 08:07 huksley

I fixed it in a different way, maybe it is worse, but I don't want to unmount component:

const ref = useRef<HTMLDivElement>(null);
return (<Modal
    ref={ref}
    onClose={_ => setOpen(false)}
    onAnimationEnd={() => {
        if (!open) {
          if (ref.current) {
            ref.current.style.opacity = "0%";
          }
          if (ref.current?.parentElement?.parentElement) {
            ref.current.parentElement.parentElement.style.opacity = "0%";
          }
        }
      }}>
     {children}
  </Modal>);

huksley avatar Jul 05 '22 08:07 huksley

When it will be fixed?

Maciej916 avatar Aug 26 '22 10:08 Maciej916

I have the exact same issue, with the versions:

  • node: v18.8.0
  • react: ^18.0.0 (still waiting for #496 to be accepted btw)
  • react-dom: "~18.1.0",
  • react-responsive-modal: ^6.2.0

ArturoDucasse avatar Sep 15 '22 17:09 ArturoDucasse

I have the exact same issue, with the versions:

  • node: v18.8.0
  • react: ^18.0.0 (still waiting for Support React 18 #496 to be accepted btw)
  • react-dom: "~18.1.0",
  • react-responsive-modal: ^6.2.0

add css it helped me .react-responsive-modal-overlay, .react-responsive-modal-container, .react-responsive-modal-modal { animation-fill-mode: forwards!important; }

AVPletnev avatar Sep 17 '22 10:09 AVPletnev

Same issue with the closing animation, adding the CSS that @AVPletnev posted solved it.

Shooshte avatar Sep 28 '22 08:09 Shooshte

Indeed @AVPletnev's CSS fixed it thanks!

xyeres avatar Oct 05 '22 22:10 xyeres

Fixed with this one line css. Credit and big thanks to @AVPletnev https://github.com/pradel/react-responsive-modal/issues/495#issuecomment-1250045781

add css it helped me .react-responsive-modal-overlay, .react-responsive-modal-container, .react-responsive-modal-modal { animation-fill-mode: forwards!important; }

ardyanrizki avatar Oct 23 '22 05:10 ardyanrizki

I think this PR needs to stay in open state because repo and NPM package is still not fixed.

huksley avatar Oct 31 '22 16:10 huksley

Fixed with this one line css. Credit and big thanks to @AVPletnev

.react-responsive-modal-overlay,
.react-responsive-modal-container,
.react-responsive-modal-modal {
  animation-fill-mode: forwards !important;
}

irtaza9 avatar Nov 05 '22 11:11 irtaza9

This is still an issue in the latest version of the package. While the suggestion helps work around it, the issue is with the package.

kahlan88 avatar Nov 10 '22 10:11 kahlan88

Fixed with this one line css. Credit and big thanks to @AVPletnev #495 (comment)

add css it helped me .react-responsive-modal-overlay, .react-responsive-modal-container, .react-responsive-modal-modal { animation-fill-mode: forwards!important; }

This fixes the issue but introduces a different one for me, makes my modal have different color values throughout its window: #FEFEFE image

#FFFFFF image

My guess is this has something to do with the animation not fully completing when using animation-fill-mode: forwards. Causing a slight bit of transparency.

Aminehassou avatar Jan 19 '23 08:01 Aminehassou

this one works for me as well!

.react-responsive-modal-modal { animation-fill-mode: forwards !important; }

BansiBrainerHub avatar Apr 14 '23 11:04 BansiBrainerHub

same issue

Mathias-21 avatar Jun 07 '23 20:06 Mathias-21