1

We've found a fairly insidious problem with a Durandaljs 2.1 application which has not really come to light previously.

Essentially the error we have received appeared to be a 404 error. However we have added a little additional error tracking and found what appears to be a timing error.

The modification we performed is as follows

viewEngine.createFallbackView = function (viewId, requirePath, err) {
    var that = this,
    message = 'View Not Found. Searched for "' + viewId + '" via path "' + requirePath + '". Error: ' + err.message;

    return system.defer(function (dfd) {
        dfd.resolve(that.processMarkup('<div class="durandal-view-404">' + message + '</div>'));
    }).promise();
};

When trying to load a specific view We get the view not found warning and the Javascript for the view is then displayed. This occurs very sporadically when the code is not minified, although seems more common on mobile devices such as Iphones. This does not occur in development atall.

However once I've used Grunt to minify the javascript the error occurs every single time in dev environment. This leads me to suspect a most insidious timing error. Has anyone else come accross this kind of problem and got any suggestions for how we might fix this. We're using Durandaljs 2.1.

The error that we receive is of the form

View Not Found. Searched for "views/stationDetails(router,dataManager){var _this=this;[Javascript ViewModelCode].fail(function(){}).promise.html".

The app always loads fine when going to the default page, however the error occurs on a separate view.

Just had another review of the code in this view. The actual durandal activate function returns a promise object, which could be relevant to the problem?

Any help gratefully received.

Ok I've done some more playing and realised there is more info relevant to this post. We are using typescript for our viewModels and this issue is related to using either instanced viewModels vs a Singleton.

So in most cases we have a singleton viewModel that we have defined as follows:

export class viewModelObject {

    constructor() { }
}


define([], () => {
   return new viewModelObject();
});

In the case where we need an instanced viewModel we've done the following:

define([], () => {
    return () => {
        return new viewModelObject();
    };
});
Captain John
  • 1,859
  • 2
  • 16
  • 30

1 Answers1

0

I haven't seen this before. Would it be possible for you to send me a simplest possible solution that reproduces the bug? I can tell you that the way you are using instanced view-models is irregular. I would expect you to return the constructor function itself. Perhaps that is the source of the issue?

EisenbergEffect
  • 3,989
  • 22
  • 26