Skip to content

Commit 55155ea

Browse files
bgrgicakadamziel
authored andcommitted
[Website] Remove client package from the list of offline mode assets (#2841)
## Motivation for the change, related issues When loading Playground I noticed an _Uncaught (in promise) TypeError: Failed to execute 'addAll' on 'Cache': Request failed_ error caused by offline mode caching. The error was triggered because _blueprints-DY7omvFh.cjs_ and _blueprints-Dg6flSLH.js_ are located in the `/client/` subdirectory on Playground.WordPress.net while the [list of offline mode assets](https://playground.wordpress.net/assets-required-for-offline-mode.json) expects these files to be in the root folder. To address the issue, this PR removes the _client_ package from the list of offline assets. We are also removing the _php-playground.html_ page from the list because it depends on the client package but isn't part of the web version of Playground. ## Testing Instructions (or ideally a Blueprint) - Follow the [Test offline support instructions](https://github.com/WordPress/wordpress-playground/blob/trunk/README.md#test-offline-support) and ensure offline mode is working
1 parent 33b8522 commit 55155ea

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

packages/playground/website/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default defineConfig(({ command, mode }) => {
151151
*/
152152
listAssetsRequiredForOfflineMode({
153153
outputFile: 'assets-required-for-offline-mode.json',
154-
distDirectoriesToList: ['./', '../remote', '../client'],
154+
distDirectoriesToList: ['./', '../remote'],
155155
}) as Plugin,
156156

157157
/**

packages/vite-extensions/vite-list-assets-required-for-offline-mode.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const patternsToNotCache = [
88
/**
99
* Static files that are not needed for the website to function offline.
1010
*/
11-
'/package.json',
12-
'/README.md',
13-
'/.DS_Store',
11+
/\/package\.json$/i,
12+
/\/README\.md$/i,
13+
/\.DS_Store$/i,
1414
'/index.cjs',
1515
/\/.*\.d\.ts$/, // No type declarations are needed at runtime.
1616
/\/lib\/.*/, // Remote lib files
@@ -73,6 +73,8 @@ const patternsToNotCache = [
7373
* Optional chunks are placed in assets/optional/ via vite.config.ts manualChunks configuration.
7474
*/
7575
/^\/assets\/optional\/.*/, // All optional assets (CodeMirror, language extensions, etc.)
76+
/^\/client\/.*/, // Client package files arent't used by the web version of Playground
77+
'/php-playground.html', // The PHP playground is a separate page that is not part of the web version of Playground
7678
];
7779

7880
function listFiles(dirPath: string, fileList: string[] = []) {
@@ -115,10 +117,7 @@ export const listAssetsRequiredForOfflineMode = ({
115117
return listFiles(absoluteDirPath)
116118
.map((file) => {
117119
file = file.replace(absoluteDirPath, '');
118-
if (file.startsWith('/')) {
119-
return file;
120-
}
121-
return `/${file}`;
120+
return join('/', file);
122121
})
123122
.filter((item) => {
124123
return !patternsToNotCache.some((pattern) => {

0 commit comments

Comments
 (0)