Issues with logic in startApp.js

It seems if you press back during launch, while startApp is running its loadJs, the settings.platformSettings.onClose() function is called, leaving the user stuck in a broken app.

Any ideas how to prevent this? (hopefully other than blocking key presses until a certain point)

thanks

logs show…

loadJS ./polyfills/babel-polyfill.js
startApp.js:275 loadJS ./polyfills/url.js
startApp.js:275 loadJS ./polyfills/fetch.js
startApp.js:275 loadJS ./lib/lightning.es5.js
startApp.js:275 loadJS ./appBundle.es5.js
startApp.js:211 :wave: App closed!
Refresh the page to restart the App

Maybe try overriding the _handleBack in your application and adding a loading = true flag

_handleBack() {
    if (this.loading) { return }

      this.closeApp()
    }

The application isn’t running yet.
The only thing that has happened at this point is the index has script src=startApp.js

You’re probably going to need to handle the keypress in the HTML. Pressing back key on a browser is like pressing the back button. During boot you can add an eventListener to handle all keypresses and just event.preventDefault and return false to prevent them from doing anything during boot and then remove it when App is fully loaded.

Tried that, the framework takes over and attaches its keyhandler still and runs the exit app function in startApp.js anyway.

The only solution that I’ve found is a really bad one, and it involves making the package then manually editing startapp by wrapping that exit function with a check for a loaded complete variable I set globally later on.

There needs to be a way to modify what gets built into startApp.js. I believe this is the only acceptable solution. Short of actually fixing the lightning sdk to not take keypresses until it’s done it’s loadJS calls.

-Drew

Hey Drew, it’s worth noting that startApp.js actually isn’t per se intended to be ran in production for a standalone App.

It’s generally used during development to mimic the setup sequence of the Metrological store, which used to be the primary target for Lightning Apps.

If you have a custom setup and are hosting your App outside of the context of the Metrological store, you might be better of using a standalone build of your App, which can be generated by running lng dist

See the relevant documentation here: LightningJS.io - Documentation and here LightningJS.io - Documentation

Michiel

1 Like

Hi @drewdub ,
facing the same issue how did u manage to over come this…
can u please help me out on this.
Thanks

I trapped the key press at the beginning of the app launch prior to loading the libraries and then released them when lightning loaded.