WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.64k stars 259 forks source link

[Website] 100% reliable deployments #1821

Closed adamziel closed 1 month ago

adamziel commented 1 month ago

Playground deployments require clearing the cache and the service worker way too often. Let's ensure a high standard of stability. All deployments should always work on all browsers without having to clear the cache.

Done is

We have an E2E suite that tests a Playground website deployment from a very old version to a new version, and ensures the following things work:

There should be no intermittent failures, stale fetch() responses, or problems with stale service workers.

Root cause of the problem

Two reasons are at play:

Dependency graphs

Deploying a new Playground version does two things:

If the previous version of Playground is still running, it will attempt to fetch the old assets – and fail:

Playground Board

This wasn't a big deal a few months ago, since a page reload would solve this, but then we've introduced the offline support in #1483 .

Caching

The offline support keeps a copy of all the accessed old assets until the new service worker is installed. This might take 24 hours or sometimes longer! During that time, visiting playground.wordpress.net would load the cached index.html file and the rest of the stale dependency graph from the previous Playground release. Since some files are only loaded on demand, we'd get a mixture of cached assets and network errors – effectively putting the app in an undefined state.

The solution

I’m 95% convinced we must always force Playground to switch to the new service worker.

However, this would require refreshing all the open tabs and would trash any temporary Playgrounds.

Therefore, we might have to store all Playgrounds in OPFS, even the temporary ones. To maintain good UX, we'd add a cleanup mechanism to hide the "stored temporary" Playgrounds after a regular page refresh, and we'd keep them visible after a page refresh triggered by a new Playground release. We could also add a “Recently archived” button to recover anything archived during the last 24 hours – cc @jarekmorawski for thoughts.

Solutions without a forced page refresh

I couldn't find any solution that would keep the Playground site working without a forced page refresh:

Playground Board

cc @brandonpayton @bgrgicak

adamziel commented 1 month ago

With #1822 and #1849 merged, this seems to be done. Let's reopen if we notice any other problems with website deployments.