MiroHibler / meteor-preloader

A Meteor "lazy-loader" for external .js and .css libraries
75 stars 3 forks source link

Exception after updating to last version 1.2.1 #18

Closed tcastelli closed 9 years ago

tcastelli commented 9 years ago

Hi there, I've just updated the package, and I got this exception on all browsers

Exception in callback of async function: Preloader.loadLibs@http://localhost:3000/packages/miro_preloader.js?07b361b1abe7bd3b9526e0031b650b48d81b0173:525:1
PreloadController<.waitOn@http://localhost:3000/packages/miro_preloader.js?07b361b1abe7bd3b9526e0031b650b48d81b0173:585:11
RouteController.prototype._runRoute/<@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:438:15
_.forEach@http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:7
RouteController.prototype._runRoute@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:437:3
Route.prototype.dispatch@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:844:10
Route/route@http://localhost:3000/packages/iron_router.js?a427868585af16bb88b7c9996b2449aebb8dbf51:710:5
boundNext@http://localhost:3000/packages/iron_middleware-stack.js?0e0f6983a838a6516556b08e62894f89720e2c44:424:16
Meteor.bindEnvironment/<@http://localhost:3000/packages

My route is defined like this (it was working correctly before the update)

Router.map(function() {
    this.route('home', {
        path: '/',
        template: 'home',
        layoutTemplate: 'HomeLayout',
        controller: 'PreloadController',
        waitOn: function () {
            return [mfPkg,subs.subscribe("fullProfile")];
        },   
        'preload': {
            'async':[Meteor.settings.public.lib.turf],
            'sync': [Meteor.settings.public.lib.modernizr,
                Meteor.settings.public.lib.leaflet,
                Meteor.settings.public.lib.esrileaflet],
            'onSync': function (filePath) {
                var file = filePath.replace(/\?.*$/, "").replace(/.*\//, "");
                switch (file) {
                    case 'modernizr.min.js':
                        try {
                            return !!Modernizr;
                        } catch (error) {
                            return false;
                        }
                        break;
                    case 'leaflet.js':
                        try {
                            return !!L;
                        } catch (error) {
                            return false;
                        }
                        break;
                    case 'esri-leaflet-basemaps.js':
                        try {
                            return !!L.esri;
                        } catch (error) {
                            return false;
                        }
                        break;
                    default:
                    {
                        return true;
                    }
                }
            }
        }
    });
});
MiroHibler commented 9 years ago

Have you tried to trace the code?

tcastelli commented 9 years ago

I don't know exactly why this is happening but i found a solution, currently, what i was trying, it was just to disable the verbose so i did this

Router.configure({
    trackPageView: true,
    'preload': {
        /*
         | Parameters can be a string (file path) or an array of strings
         */
        // Added in v1.2.1 - this one works only in Router.Configure!
        'verbose': false,  // Show loading messages in console,

    }
});

And the rest of the things were specified in the route itself. (I got the error by doing so). To make it work, it seems that there needs to be something for preloader to do ath the global level, but since i didnt want to add any libraries or anything on the global level, i just added

        // CSS style(s) to load
        'styles' : '' // or []

and now it's working. Hope it helps to track down the issue

MiroHibler commented 9 years ago

Oh, ok, it's more clear now - let check that...

DanielRHarris commented 9 years ago

Having the same issue, and same solution as @tcastelli works.

MiroHibler commented 9 years ago

Fixed with v1.2.3.

Thanks guys! :)

DanielRHarris commented 9 years ago

Thanks for working on this despite it being an easy bug to get around! Just wanted to let you know that it still isn't working though - still getting the same error with the latest version (1.2.3)

https://gist.github.com/DanielRHarris/22b967a24329ecea1434

MiroHibler commented 9 years ago

So, to clear it up, the bug occurs only if you DON'T set any styles to be loaded, correct?

DanielRHarris commented 9 years ago

That's correct.

styles can be empty (ie. '' or []), but it needs to be included along with whatever sync, or async in order to work.

MiroHibler commented 9 years ago

It should be fixed now :)

DanielRHarris commented 9 years ago

Works perfectly now, thanks!