-
Notifications
You must be signed in to change notification settings - Fork 275
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
Project Scoping: Offline Support #1600
Conversation
|
||
- [x] [PWA support](https://github.com/WordPress/wordpress-playground/pull/1086) | ||
- [ ] [Backfill remote WordPress assets](https://github.com/WordPress/wordpress-playground/pull/1532) | ||
- [ ] Backfill Playground assets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways assets can be backfilled.
- When the site requests an asset we can cache it using a service worker.
- We can cache files from a static list when the Playground boots.
When the site requests an asset we can cache it using a service worker.
This method is preferred because it avoids maintaining a list of files to download.
The challenge is that it can start only after the service worker loads.
To start loading data as early as possible we will move registerServiceWorker
to run before spawnPHPWorkerThread
in packages/playground/remote/src/lib/boot-playground-remote.ts
.
We can cache files from a static list when the Playground boots.
This could happen at the same time when we download WordPress assets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To start loading data as early as possible we will move registerServiceWorker to run before spawnPHPWorkerThread in packages/playground/remote/src/lib/boot-playground-remote.ts.
I did this in #1606 and can confirm that it will allow us to load WordPress and PHP assets without backfilling. This will make the implementation simpler because the backfill script won't need to know what's the current PHP and WP version.
Most other items will need to be backfilled.
Here is an example of how items load with #1606
First load
/favicon.ico
/worker-thread-5bd5ae4a.js
/assets/sqlite-database-integration-fd6f4063.zip
/assets/wp-6.5-264f1631.zip
/assets/php_8_0-a8925787.js
/assets/php_8_0-3584e351.wasm
/src/fonts/1258fcda79d43bef/inter_Inter-Regular.woff
/src/fonts/f86c32ba0f42a842/inter_Inter-SemiBold.woff
/src/fonts/8efb053b450b4a72/inter_Inter-Medium.woff
/src/fonts/62c967bbd6d11106/inter_Inter-Light.woff
/avatar/e6d67fed862c439aa6e911ce49c7857d
Second load
Cache miss
/gtag/js
/assets/index-9b5e396e.js
/assets/modulepreload-polyfill-3cfb730f.js
/assets/preload-helper-cf010ec4.js
/assets/index-d60708af.css
/assets/main-7bf730a2.css
/g/collect
/remote.html
/assets/wordpress-c3703a25.js
/assets/remote-b5d5f2da.css
Cache hit
/favicon.ico
/worker-thread-5bd5ae4a.js
/assets/sqlite-database-integration-fd6f4063.zip
/assets/wp-6.5-264f1631.zip
/assets/php_8_0-a8925787.js
/assets/php_8_0-3584e351.wasm
/src/fonts/1258fcda79d43bef/inter_Inter-Regular.woff
/src/fonts/f86c32ba0f42a842/inter_Inter-SemiBold.woff
/src/fonts/8efb053b450b4a72/inter_Inter-Medium.woff
/src/fonts/62c967bbd6d11106/inter_Inter-Light.woff
/avatar/e6d67fed862c439aa6e911ce49c7857d
/g/collect
[For offline support](#1600) we need to load the service worker as early as possible in the boot process. Booting early will allow fetch caching to cache more files on the first making the backfill of assets simpler. Read the full research recap here #1600 (review) ## Implementation details To move `registerServiceWorker` to the start of the boot process we had to generate the scope in `bootPlaygroundRemote` and pass it to the PHP worker thread together with other startup options. The service worker had to be registered before spawning the PHP worker thread to ensure WP and PHP assets were cached. But the service worker also depends on the `phpApi` returned by `spawnPHPWorkerThread`. We had to register the service worker first, after that, spawn the PHP worker thread, and then set the `phpApi`. This PR also includes changes from #1574 because they allow us to pass the scope. ## Testing Instructions (or ideally a Blueprint) - Ensure all tests pass --------- Co-authored-by: Adam Zieliński <adam@adamziel.com>
[Playground will soon be able to work offline](#1600), but some features like GitHub exports still require internet to work. When offline users shouldn't be able to: - Change PHP versions - Change WordPress versions - Enable networking - Change if extensions are loaded or not - Export to GitHub - Import from GitHub - Report error Some of these might get offline support in the future, but they won't be available in v1. ## Implementation details The `PlaygroundReduxState` store now has a `offline` selector. This selector is used by the _Customize Playground_ form and the menu to disable buttons for functionalities that don't work offline. ## Testing Instructions (or ideally a Blueprint) - Checkout this branch - Open Playground http://127.0.0.1:5400/website-server/ - Go offline (in Chrome Dev Tools > Application > Service Worker > Offline checkbox) - Open the _Customize Playground_ - Confirm that these features are disabled - Change PHP versions - Change WordPress versions - Enable networking - Change if extensions are loaded or not - Open the menu (upper right corner) - Confirm that these features are disabled - Export to GitHub - Import from GitHub - Report error ![Screenshot 2024-07-12 at 13 55 19](https://github.com/user-attachments/assets/8a5f174e-22e2-409d-9fd4-a2209f71bbb9) ![Screenshot 2024-07-12 at 13 55 26](https://github.com/user-attachments/assets/11cfccd3-ff55-41df-b478-5a506b85cb81) --------- Co-authored-by: Adam Zieliński <adam@adamziel.com>
Progress update July 16thAll offline mode dependencies are now merged and I'm wrapping up Cache Playground assets to enable offline support. I noticed that manifest.json is broken, so I added a fix for manifest.json URLs. |
@brandonpayton @adamziel how do you feel about moving project discussions to https://make.wordpress.org/playground/? |
@bgrgicak Makes sense to me, although, other than the Firefox issue and a few tactical todos, this project seems to be shipped now? It would still make sense to write an announcement post on that make blog. Would you please draft one for core contributors to review, since you were the one leading this? |
Yes, it's done now, we don't need to post a project scoping post. |
@adamziel who should I ask for a review? I have a draft, but I'm unsure about the format because this is the first post. The post is short and doesn't include technical details. I also wanted to mention technical limitations to ensure it's clear what's possible. |
@adamziel should we merge this PR (after I update the document), or should we drop it? Initially, I thought the project file could be useful to have in the codebase, but we documented everything in the code and I don't think that we need it. |
@bgrgicak that draft is a great start! Here's two things I'm missing:
Also, I'm not sure what does it mean that PWA uses the current URL to install the app, or what are the settings in this paragraph:
Is this a general limitation of PWAs? If yes, then perhaps we can skip it. If it's specific to Playground, let's explain why does this matter, what's the annoyance/limitation for the user. Also cc @brandonpayton and @bph for thoughts and reviews. |
Dropping it sounds reasonable. Using markdown for scoping discussions sounded like a good avenue to explore, but it seems like the user experience is not that great and GitHub discussions would be more helpful. |
We published Introducing Offline Mode and PWA Support for WordPress Playground on Make. |
Start date: June 18th 2024
ETA: July 22nd 2024
Updates: Weekly
Status: In progress
See project description here.