Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

microbit-robert
Copy link
Collaborator

@microbit-robert microbit-robert commented Apr 17, 2024

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.

Copy link

github-actions bot commented Apr 17, 2024

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

@microbit-matt-hillsdon
Copy link
Collaborator

all available languages are precached

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

@microbit-robert
Copy link
Collaborator Author

microbit-robert commented Apr 18, 2024

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.

//const url = `https://review-python-simulator.usermbit.org/${branch}/simulator.html`;
// TODO: Revert.
const branch = "service-worker";
const url = `https://review-python-simulator.usermbit.org/${branch}/simulator.html`;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Revert before merge.

@microbit-robert microbit-robert changed the title [DRAFT - DO NOT MERGE] PWA attempt using vite pwa plugin [DRAFT - DO NOT MERGE] Add PWA functionality including offline mode Apr 24, 2024
src/index.tsx Outdated
Comment on lines 14 to 16
// Cache runtime resources on first load.
// See https://github.com/GoogleChromeLabs/pwa-wp/issues/180.
onRegisteredSW(_, registration) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best or most efficient way? It might be the only way.

@microbit-robert
Copy link
Collaborator Author

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

image

Comment on lines +27 to +28
# Optionally disable the PWA config (service worker and web manifest)
# DISABLE_PWA: '1'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's confirm what the default behaviour should be.

@@ -60,6 +67,7 @@ const allFlags: FlagMetadata[] = [
{ name: "noLang", defaultOnStages: [] },
{ name: "translate", defaultOnStages: [] },
{ name: "noWelcome", defaultOnStages: ["local", "REVIEW"] },
{ name: "pwa", defaultOnStages: ["REVIEW"] },
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs more thought/discussion. If you install the PWA, close it, then reopen it, you'll lose the flag and the ability to add the flag. In the meantime, this change will make the review branch a bit more useful for testing.

Note: You don't need to install the app to test its offline capabilities.

Comment on lines +43 to +48
return html.replace(
`<link rel="manifest" href="${
process.env.BASE_URL ?? "/"
}manifest.webmanifest">`,
""
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. This works, but feels fragile.

@microbit-matt-hillsdon microbit-matt-hillsdon marked this pull request as ready for review May 22, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants