python-editor-v3 icon indicating copy to clipboard operation
python-editor-v3 copied to clipboard

[DRAFT - DO NOT MERGE] Add PWA functionality including offline mode

Open microbit-robert opened this issue 10 months ago • 4 comments

Notable behaviours:

  • Fallbacks to English when changing language offline (when the selected language assets aren’t cached).
  • Shows image placeholders for uncached images when offline.
  • The app will automatically trigger a page reload when it detects the service worker has been updated. The service worker is updated when any of the build assets are updated.

microbit-robert avatar Apr 17 '24 15:04 microbit-robert

Preview build will be at https://review-python-editor-v3.microbit.org/pwa/

github-actions[bot] avatar Apr 17 '24 15:04 github-actions[bot]

all available languages are precached

Does that mean everyone pays the cost of every language now? Before interactivity or after/in the background?

microbit-matt-hillsdon avatar Apr 18 '24 09:04 microbit-matt-hillsdon

all available languages are precached

Does that mean everyone pays the cost of every language now? Before interactivity or after/in the background?

~~For this version, yes. We need to be more specific in what we precache. Maybe nothing language specific and save that for runtime. It does feel like the plugin might not suit our needs. We'll either end up creating just the service worker from scratch, or ditch the plugin and do everything from scratch.~~

Edit: This has now been resolved by using a mixture of precaching for our fallback language (English) and runtime caching for all other languages.

microbit-robert avatar Apr 18 '24 09:04 microbit-robert

Toast shown when changing language while offline and language assets are not already cached. Text is a working placeholder and needs discussion.

image

microbit-robert avatar Apr 26 '24 14:04 microbit-robert

image

This feels a bit odd when in PWA mode as there's no obvious affordance to reload the page. Ideally we'd find a more neutral phrasing.

Perhaps it's best not to change the user's language in this circumstance? That removes the English bias and prevents the weird app state of having chosen but not used a language. So maybe:

Language not available offline

Make sure you are online then try again.

microbit-matt-hillsdon avatar May 29 '24 08:05 microbit-matt-hillsdon

I'll merge this tomorrow when I'm more available for any fallout.

microbit-matt-hillsdon avatar May 29 '24 16:05 microbit-matt-hillsdon

This isn't working in practice as we used scoped service workers but the scope is /v/beta/ but typically access is at /v/beta for staging/production. Ideally we wouldn't redirect to the less pretty URLs.

We could register against a slashless scope by adding a header. It's a prefix match so that's a bit awkward, e.g. /v/3 would also match /v/31 and /v/beta would match /v/betamax. The former seems worth some consideration. Alternatively we just have one and accept the extra reload when switching between versions.

microbit-matt-hillsdon avatar May 30 '24 09:05 microbit-matt-hillsdon

We could register against a slashless scope by adding a header. It's a prefix match so that's a bit awkward

We did this and it now seems to be working. Still behind the flag you need to set in localStorage.

microbit-matt-hillsdon avatar May 30 '24 11:05 microbit-matt-hillsdon