cibernox / ember-power-calendar

Powerful and customizable calendar component for Ember
http://www.ember-power-calendar.com
Other
211 stars 118 forks source link

firefox moment issue. #47

Open koryteg opened 7 years ago

koryteg commented 7 years ago

firefox is freezing when hitting this method if you pass a moment.js date object to the addon.

    lastDay: function lastDay(calendar) {
      var localeStartOfWeek = this.get('localeStartOfWeek');
      var lastDay = calendar.center.clone().endOf('month');
      var localeEndOfWeek = (localeStartOfWeek + 6) % 7;
      while (lastDay.isoWeekday() % 7 !== localeEndOfWeek) {
        lastDay.add(1, 'day');
      }
      return lastDay;
    },
cibernox commented 7 years ago

@koryteg only firefox? Interesting. I'll check it. Can you check if the tests pass on firefox and if they do, create a failing test that exercises this error?

koryteg commented 7 years ago

yeah I will try and get something going on a PR.

boyanyordanov commented 7 years ago

We had a similar issue recently, but it got both Chrome and Firefox freezing. I tracked it down to passing null as the selected date to the calendar. However it might be the same issue.

bahdvp commented 7 years ago

@boyanyordanov how did you resolve? does selected date accept an empty object just as well?

cibernox commented 7 years ago

FWIW, I did not find a way to reproduce this, but I suspect the reason. There is a part of the code where I compare dates on a while and keep iterating until a date is before or after another one. So far so good, but if the moment is malformed, that loop never ends causing the freeze.

Why can that happen in one browser and not in another? Because the only date format that is guaranteed to work in all browsers is ISO 8601. Any other format may or may not work. Chrome per example is pretty good at parsing malformed dates. Firefox is more strict.

I suspect this is the root cause, if anyone wants to investigate.

NLincoln commented 7 years ago

We've run into this issue as well.

I believe our test case for the fix was something like:

{{power-calendar date="Invalid Date"}}

Or something similar

bahdvp commented 7 years ago

@NLincoln Cheers.

@cibernox I have not been able to reproduce either. A tester reported it as an issue but didn't see an immediate cause. If I ever get time to investigate further I'll let you know. Thanks for the lead.

boyanyordanov commented 7 years ago

@bahdvp I am sorry, I was not able to write earlier. We just don't initialize the values and have checks in the parent component to ensure we always pass down a valid date.