angular-toastr icon indicating copy to clipboard operation
angular-toastr copied to clipboard

Immediatly closing new toasters before the document is ready causes errors

Open iJungleboy opened this issue 10 years ago • 6 comments

I have an application which retrieves data and shows an info-toaster that it's "loading". This message is cleared using toastr.clear(variableOfPreviousMsg) when the data arrives.

If the data comes back too quickly, AngularJS throws an error about a parent being undefined. image

If I debug the error usually doesn't appear, so I cornered it into a timing issue. It seems that the "variableOfPreviousMsg" contains a parent (another dom-element) but that one does not have one yet if things go too fast.

btw: the value of .isOpen is still false at the time of the error, and it's true if everything takes a bit longer. So basically I think the clear-behaviour should kind of not kill a not-open-yet but rather prevent it from opening...

iJungleboy avatar Oct 24 '15 12:10 iJungleboy

Interesting, but it is the kind of issues that are hard to debug. Perhaps with a quick timeout to close it after showing it.

Will try later.

Thanks for the report.

Foxandxss avatar Oct 24 '15 12:10 Foxandxss

My workaround is now

            if (t.msg.isOpened)
                toastr.clear(t.msg);
            else {
                $timeout(300).then(function() {
                        toastr.clear(t.msg);
                    }
                );
            }

this solves it, but of course is not very sexy - especially since a very fast load wouldn't even need to show the loading-toastr.

iJungleboy avatar Oct 24 '15 12:10 iJungleboy

Don't worry. I will fix it ASAP. El 24/10/2015 2:45 p. m., "iJungleboy" [email protected] escribió:

My workaround is now

        if (t.msg.isOpened)
            toastr.clear(t.msg);
        else {
            $timeout(300).then(function() {
                    toastr.clear(t.msg);
                }
            );
        }

this solves it, but of course is not very sexy - especially since a very fast load wouldn't even need to show the loading-toastr.

— Reply to this email directly or view it on GitHub https://github.com/Foxandxss/angular-toastr/issues/134#issuecomment-150808694 .

Foxandxss avatar Oct 24 '15 12:10 Foxandxss

You're awesome :+1:

iJungleboy avatar Oct 24 '15 12:10 iJungleboy

I can't reproduce it.

Could you please give me more information about the error? Non minified code and what line is the one triggering the error on my code.

A plunker reproduction would be really lovely.

I am trying with:

var toast2;
$timeout(function() {
  toast2 = toastr.info('We are open today from 10 to 22', 'Information');
}, 100);
$timeout(function() {
  toastr.clear(toast2);
}, 150);

changing the second timeout value to less, but no error whatsoever.

Will keep trying.

Foxandxss avatar Oct 24 '15 14:10 Foxandxss

Ok. I'll try to assemble something; my application is very large (ca. 10k lines) so I'll have to find a way to extract a toastr-timer-demo...

iJungleboy avatar Oct 25 '15 09:10 iJungleboy