LearnNewsExamplesServices
Frontmatter
id1166
titleBreaking Change: Adjust the Neo.onStart() app starting points
stateClosed
labels
enhancement
assigneestobiu
createdAtSep 3, 2020, 7:34 PM
updatedAtSep 10, 2020, 12:16 AM
githubUrlhttps://github.com/neomjs/neo/issues/1166
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtSep 10, 2020, 12:16 AM

Breaking Change: Adjust the Neo.onStart() app starting points

Closed v8.1.0 enhancement
tobiu
tobiu commented on Sep 3, 2020, 7:34 PM

Hello everyone,

this is the first breaking change in a long time, but I am afraid it needs to happen.

So far, our app.mjs files looked like:

import MainContainer from './view/MainContainer.mjs';

Neo.onStart = () => Neo.app({
    appPath : 'apps/shareddialog/',
    mainView: MainContainer,
    name    : 'SharedDialog'
});

While this is perfectly fine for single page apps, it is actually not for the SharedWorkers context.

If we load our first app, we define Neo.onStart() and trigger it. Now if we load a different app, we will override Neo.onStart() and trigger the new method. Works fine as well. The problem starts, when we want to reload our first app window:

Browsers are "smart", so they will cache the module. In this case, Neo.onStart() will not get overridden again and we will trigger the last version of it.

Results are:

Screenshot 2020-09-03 at 17 32 55

(look close at the URLs)

To fix this, I will adjust the starting points to the following:

import MainContainer from './view/MainContainer.mjs';

const onStart = () => Neo.app({
    appPath : 'apps/shareddialog/',
    mainView: MainContainer,
    name    : 'SharedDialog'
});

export {onStart as onStart};

We will export the onStart() method and no longer use Neo.onStart() at all. This change ensures, that we will always get the correct method.

While this is easy to fix for the dev mode, it is a bit painful for the webpack based dist versions.

I found a way that works, although it is not exactly beautiful:

    onLoadApplication(data) {
        let me = this,
            path;

        if (data) {console.log(data);
            me.data = data;
            Neo.config.resourcesPath = data.resourcesPath;
        }

        if (!Neo.config.isExperimental) {
            path = data.path.replace('.js', '.mjs');
            path = path.substring(0) === '.' ? path : '.' + path;

            __webpack_require__.c[path].exports.onStart();

            //Neo.onStart();

            if (Neo.config.hash) {
                setTimeout(() => HashHistory.push(Neo.config.hash), 5);
            }
        } else {
            import(
                /* webpackIgnore: true */
                `../../${me.data.path}`).then(module => {
                    // Neo.onStart();
                    module.onStart();

                    if (Neo.config.hash) {
                        // short delay to ensure Component Controllers are ready
                        setTimeout(() => HashHistory.push(Neo.config.hash), 5);
                    }
                }
            );
        }
    }

I will adjust all starting points now and afterwards the build scripts (including the npx neo-app repo).

Best regards, Tobi

tobiu added the enhancement label on Sep 3, 2020, 7:34 PM
tobiu assigned to @tobiu on Sep 3, 2020, 7:34 PM
tobiu referenced in commit fd33c26 - "Breaking Change: Adjust the Neo.onStart() app starting points #1166 => main logic (worker.App: onLoadApplication())" on Sep 3, 2020, 7:50 PM
tobiu referenced in commit 914bfcf - "#1166 Adjusted the starting points for all apps inside the apps folder" on Sep 3, 2020, 7:54 PM
tobiu referenced in commit 7006ce1 - "#1166 Adjusted the starting point for the docs app" on Sep 3, 2020, 7:55 PM
tobiu referenced in commit 7130847 - "#1166 Adjusted the starting points for all example apps" on Sep 3, 2020, 8:12 PM
tobiu referenced in commit adcb088 - "#1166 Adjusted the todo list tutorial" on Sep 3, 2020, 8:17 PM
tobiu referenced in commit 20c814a - "#1166 Updated the createApp script" on Sep 3, 2020, 8:19 PM
tobiu referenced in commit 1becbc3 - "#1166 removed onStart from the Neo.mjs file" on Sep 3, 2020, 8:39 PM
tobiu closed this issue on Sep 10, 2020, 12:16 AM