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

Should we allow calling the close callback more than once? #861

Open
lolmaus opened this issue Jul 5, 2023 · 1 comment
Open

Should we allow calling the close callback more than once? #861

lolmaus opened this issue Jul 5, 2023 · 1 comment

Comments

@lolmaus
Copy link
Collaborator

lolmaus commented Jul 5, 2023

Hi!

@herzzanu and me have investigated a flaky test in a huge app.

After some frustrating investigation we have discovered, that the cause of test failures was that a modal's @close callback was called twice.

The frustration was caused by trhee parts:

  • everything is async, so the stack trace points at a promise that had been caught by Ember Backburner or something, and the stack trace does not point at the code of the promise callback;
  • we have a chain of ember-concurrency tasks threading through multiple components; a modal is opening a modal, etc;
  • tests never failed locally when the browser tab was focused; tests would sometimes fail when the tab was not focused. 🤯

The specific error turned out to be "calling set on destroyed object", with stack trace pointing at this line:
https://github.com/mainmatter/ember-promise-modals/blob/v4.0.0/addon/components/modal.js#L148

The solution on our side was to make sure the modal was not being closed twice.

But I wonder, if this should even be a developer's concern? Why not let developers close the modal more than once?

At the very least, we could wrap the set into if (!this.isDestroying && !this.isDestroyed). Or we could make the close callback return early if it is called more than once.

@nickschot
Copy link
Member

nickschot commented Jul 5, 2023

My thoughts:

Simplest solution is probably to use some kind of boolean (probably not isDestroying since I think that's a reserved thing on EmberObjects?) that prevents the entire close sequence that allows for the animation to run from running multiple times. I don't think it can be interrupted and we probably don't want that possibility anyway.

Ideally it'd also have a dev-time assertion when it does happen to be running multiple times so that we spot the issue easier. Something like "can't close modal that is already closing".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants