OpenF2 / F2

Redefining web integration for the financial services community
Apache License 2.0
129 stars 62 forks source link

Unable to set property 'app' of undefined or null reference #265

Closed ecirmada closed 2 years ago

ecirmada commented 8 years ago

Hey guys,

I have F2 running in an SPA and have identified a race condition with a setTimeout on line 292 of container.js:

    /**
     * Instantiates each app from it's appConfig and stores that in a local private collection
     * @method _createAppInstance
     * @private
     * @param {Array} appConfigs An array of {{#crossLink "F2.AppConfig"}}{{/crossLink}} objects
     */
    var _createAppInstance = function(appConfig, appContent) {
        // instantiate F2.UI
        appConfig.ui = new F2.UI(appConfig);

        // instantiate F2.App
        if (F2.Apps[appConfig.appId] !== undefined) {
            if (typeof F2.Apps[appConfig.appId] === 'function') {

                // IE
                setTimeout(function() {
                    _apps[appConfig.instanceId].app = new F2.Apps[appConfig.appId](appConfig, appContent, appConfig.root);
                    if (_apps[appConfig.instanceId].app['init'] !== undefined) {
                        _apps[appConfig.instanceId].app.init();
                    }
                }, 0);

            }
            else {
                F2.log('app initialization class is defined but not a function. (' + appConfig.appId + ')');
            }
        }
    };

The issue I'm having is when we destroy the app (when the user navigates away) before the 'async' code can execute. _apps[appConfig.instanceId] doesn't exist any more, but the setTimeout triggers anyway. I've created a gist with a patch in it.

timburcham commented 8 years ago

Hey Charlie, thank you for the patch. This is in review with the admins for F2 to determine the best way to merge into 1.4.