Collaborne/paper-date-picker-item

Reloading moment.js breaks other components

fairsayan opened this issue · 1 comments

Hi,
in my app I load momentjs in my index.html:

    <script src="../bower_components/moment/min/moment-with-locales.min.js"></script>
    <script src="../bower_components/moment-timezone/builds/moment-timezone-with-data-2010-2020.min.js"></script>

because I need it in different pages.
In one of them I use paper-date-picker-item, but after this page is loaded, the constructor moment.tz and all the others functions related with moment-timezone are undefined.
I dug into this issue and I discovered that you call moment-element to provide another version of moment (without timezone).
I commented the loading stuff in moment-element and now everything works fine.

I tried to put my <script> to load moment-timezone inside each component that uses it, but it works only for the first time I visit the component and after, if I load paper-date-picker-item and I go back to my component, I will obtain moment.tz is undefined because moment-element will have overwritten the moment object without moment.tz and the browser won't load my moment version again since my component is already loaded.

So what? My suggestion is to get riddle of moment-element and ask in the document to load in advance a proper version of momentjs instead of trying to manage all the possible different versions of momentjs.

Thanks for your feedback, @fairsayan

I understand the issue but I'm not sure if the is the right level to solve it: requires moment.js and should therefore also define this dependency (otherwise users will just forget adding the moment library).
I'd claim the problem is higher up: moment.js not being able to get loaded multiple times or - in case it's documented that one shouldn't do this (I didn't check) - not avoiding to load the library multiple times.

Btw, be careful with importing the moment JS directly via <script> in case you use vulcanization: https://medium.com/collaborne-engineering/polymer-how-we-wasted-1-5-mb-by-importing-external-libraries-wrongly-we-vulcanize-our-polyme-3534ae614454#.si6r64hd1