IDEMSInternational / open-app-builder

PLH App Frontend
GNU General Public License v3.0
5 stars 24 forks source link

[BUG] Slow initial load on web preview on mobile #2126

Closed jfmcquade closed 10 months ago

jfmcquade commented 10 months ago

Describe the bug When accessing the web preview of the app on mobile, the page hangs for about a minute before the content is rendered. This was first observed for plh-facilitator-my deployment, but seems to be an issue for all web previews. See screenshots section for more details

App version 0.16.21

To Reproduce On a mobile browser, navigate to plh-facilitator-my.web.app (or another web preview). On my device (Pixel 8), the page is blank for around a minute before the app loads.

Screenshots and videos The following screenshots are of Chrome devtools connected to my phone in USB debugging mode. They show the console logs of the startup services intialising. In each case, there is a pause of around 60 seconds after the TemplateAsset service finishes initialising before the LocalNotifications service logs that its initialisation has failed (along with the LocalNotificationInteraction service and Campaigns service). The screen just shows the background colour of the app with no content until this point, at which the expected app content renders.

plh-facilitator-my.web.app

Screenshot 2023-11-03 at 16 40 12

The Performance tab doesn't seem helpful – it only lets me record for 45 seconds, which isn't long enough to capture the eventual page load

Screenshot 2023-11-03 at 16 44 12

plh-tz

Screenshot 2023-11-03 at 16 50 31

idems-debug.web.app

Screenshot 2023-11-03 at 16 51 54

Additional context It appears the issue is with the local notifications service itself, and specifically its initialisation.

One possible culprit is the requestPermission() method. The fact that this bug is only present in the specific case of visiting the web preview on mobile suggests that it's likely related to some native mobile features, for example, the issue could be with the check we run within requestPermission() to see if the platform is native, or else with Capacitor's own LocalNotifications.requestPermissions(), also within this method. I note in the docs for Capacitor's LocalNotifications plugin, there is mention of changes between Android 12 and 13 with regards to LocalNotifications.requestPermissions(), so possibly this issue was introduced by the migration to Capacitor 5 and support for Android 13, #2046.

Screenshot 2023-11-03 at 17 18 46

As the local notifications service init() method involves some database activity, and as this issue affects all web previews on mobile and has only just been observed, it is possible that the issue is related to the recent changes to the database(s) and APIs introduced with #2115. However I'm not sure at this stage (does the db service even connect to the remote databases?).

chrismclarke commented 10 months ago

Yeah definitely seems to be an issue with using notification on chrome for android - which is weird because it actually works fine in my duckduckgo browser (just not chrome)

I think ideally we need to allow the localnotification service to not crash other services if not supported

chrismclarke commented 10 months ago

Opened #2128 to try address