Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The target and the `build:wordpress-frame` preview assemble the upload with the
`bin/assemble-website.mjs`, so preview checks cover every published page. The single `apply-update.sh`
installs the build as the public `releases/<id>/` directory, moves its PHP endpoints
to the Nginx-denied `.playground-releases/<id>/`, and copies entry pages plus a root
`/sw.js` loader to the web root. Pages needing custom headers stay PHP-served.
`/sw.js` worker to the web root. Pages needing custom headers stay PHP-served.
Its PHP steps live in `apply-update.php`, which it calls with arguments only.
The cacheable `playground-wordpress-builds:validate-static-documents` target validates
WordPress HTML, SVG, XHTML, and XML with a parsed-document DOMPurify check. Asset refresh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function getWorkerUrl(): string {
}

// A worker controls only paths below its own URL, so static releases register the
// root /sw.js loader, which imports this release's worker.
// active worker at /sw.js.
export const serviceWorkerUrl = new URL(
usesMultiReleaseDirectoryLayout ? '/sw.js' : serviceWorkerPath,
origin
Expand Down
6 changes: 3 additions & 3 deletions packages/playground/remote/src/lib/wordpress-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { portToStream, streamToPort } from '@php-wasm/universal';
import { buildVersion } from 'virtual:remote-config';

const scope = new URL(location.href).searchParams.get('scope');
// The host serves /sw.js as a same-origin loader for the app's public worker.
// The host serves /sw.js as the active release worker.
// Keep this URL literal: the service worker also bundles this bridge for offline HTML.
const workerUrl = new URL('/sw.js', location.origin);
// PRE_SANDBOX_CDN_COMPAT: introduced by #4526, before release directories, when
Expand All @@ -48,8 +48,8 @@ try {
type: 'module',
updateViaCache: 'none',
});
// register() can reuse this loader URL's existing registration without checking
// its imported app worker. Finish that check before selecting the worker to wait for.
// register() can reuse this URL's existing registration without checking for
// a new worker. Finish that check before selecting the worker to wait for.
await registration.update();
} catch (error) {
// Keep offline startup working with an installed worker, as the app's own
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/website-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The main deployment workflow runs `deploy-website.sh` with
unique `PLAYGROUND_RELEASE_ID`, builds the website for those values, uploads the
build and this directory over SSH, and runs the single `apply-update.sh` script. `apply-update.sh` checks both hosts and the build, installs the public and
private release directories, backs up the root files it replaces, replaces the PHP
entry, copies the entry pages, and installs the root `/sw.js` loader before purging
entry, copies the entry pages, and installs the root `/sw.js` worker before purging
the edge. Its PHP steps live in `apply-update.php`, which receives values only as
arguments. See the [two-host deployment guide](wordpress-frame/README.md)
for required WP Cloud settings, the Nginx preflight checks, and rollback.
Expand Down Expand Up @@ -112,7 +112,7 @@ If bundled Firefox cannot launch locally, set

WP Cloud's edge cache purge clears only the primary domain unless a domain is
named, so `apply-update.sh` purges each hostname. Nginx lets the edge cache `.js`
files, including the root `/sw.js` loader, for a year, so both purges are needed.
files, including the root `/sw.js` worker, for a year, so both purges are needed.
The purge returns before every edge node drops its copies; the checks wait for both
hosts' root files to name the new release.

Expand Down
3 changes: 1 addition & 2 deletions packages/playground/website-deployment/apply-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ function activate( $root, $backups, $release, $retention, $app_origin, $wordpres
$sources[ $path ] = $file->getPathname();
}
}
write_file( "$private/root-sw.js", 'import ' . json_encode( "/releases/$release/sw.js", JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR ) . ";\n" );
$sources['sw.js'] = "$private/root-sw.js";
$sources['sw.js'] = "$public/sw.js";
$next = array(
'release' => $release,
'previousRelease' => $manifest['release'] ?? null,
Expand Down
12 changes: 7 additions & 5 deletions packages/playground/website-deployment/check-deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ info() { echo "INFO $1"; }
request() {
local url="$1"
shift
: > "$WORK/body"
STATUS="$(curl --silent --show-error --max-time 60 --path-as-is \
--dump-header "$WORK/headers" --output "$WORK/body" \
--write-out '%{http_code}' "$@" "$url")" || STATUS=000
Expand Down Expand Up @@ -67,11 +68,12 @@ report_caching() {
# The edge cache purge returns before every edge node drops its old copies, so
# root files can name the previous release for a short time after a deployment.
if [ -n "$EXPECTED_RELEASE" ]; then
loader="import \"/releases/$EXPECTED_RELEASE/sw.js\";"
# Matches the worker and the loader that older releases installed at /sw.js.
worker_base="\"/releases/$EXPECTED_RELEASE/"
started=$SECONDS
until curl --silent --max-time 30 "$APP/release.json" | grep -qF "\"release\":\"$EXPECTED_RELEASE\"" &&
curl --silent --max-time 30 "$APP/sw.js" | grep -qF "$loader" &&
curl --silent --max-time 30 "$WORDPRESS/sw.js" | grep -qF "$loader"; do
curl --silent --max-time 30 "$APP/sw.js" -o "$WORK/worker" && grep -qF "$worker_base" "$WORK/worker" &&
curl --silent --max-time 30 "$WORDPRESS/sw.js" -o "$WORK/worker" && grep -qF "$worker_base" "$WORK/worker"; do
if [ $((SECONDS - started)) -ge "${PLAYGROUND_CHECK_WAIT:-300}" ]; then
break
fi
Expand All @@ -95,12 +97,12 @@ if [ -n "$EXPECTED_RELEASE" ] && [ "$RELEASE" != "$EXPECTED_RELEASE" ]; then
fi
BASE="/releases/$RELEASE"

# Both hosts load the active release's worker through the root loader. Nginx lets
# Both hosts load the active release's worker at /sw.js. Nginx lets
# the edge cache it for a year, so this also shows the deployment purged both hosts.
for host in "$APP" "$WORDPRESS"; do
request "$host/sw.js"
expect_status 200 "$host/sw.js"
expect_body "import \"$BASE/sw.js\";" "$host/sw.js imports the active release's worker"
expect_body "\"$BASE/" "$host/sw.js names the active release"
report_caching "$host/sw.js"
request "$host$BASE/sw.js"
expect_status 200 "$host$BASE/sw.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ The previous layout served every file through PHP from a hidden release. The
first deployment of this layout adds the public release, root copies, and root
`/sw.js` next to it and replaces `custom-redirects.php`; the old hidden releases
stay in place. Browsers update their existing `/sw.js` registrations on both hosts
to the new loader, which chooses its role by origin. Tabs opened before the switch
to the active worker, which chooses its role by origin. Tabs opened before the switch
can no longer load their old root `/assets/` chunks, as with any earlier deployment.

## Verify and roll back
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,7 @@ process.stdout.write(process.argv.at(-1).includes('/sw.js?') ? '200' : '403');
// PHP endpoints never enter the public tree, where Nginx would run them.
await assert.rejects(stat(join(webRoot, 'releases/A/status.php')));
await stat(join(webRoot, '.playground-releases/A/files/status.php'));
assert.equal(
await readFile(join(webRoot, 'sw.js'), 'utf8'),
'import "/releases/A/sw.js";\n'
);
assert.equal(await readFile(join(webRoot, 'sw.js'), 'utf8'), '// worker A');
assert.equal(
JSON.parse(await readFile(join(webRoot, 'release.json'), 'utf8'))
.release,
Expand Down Expand Up @@ -446,7 +443,7 @@ require ${JSON.stringify(join(webRoot, 'custom-redirects.php'))};
);
assert.equal(
await readFile(join(backups, 'B/sw.js'), 'utf8'),
'import "/releases/A/sw.js";\n'
'// worker A'
);
await assert.rejects(
install('B', await makeBuild('B')),
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/website/bin/wordpress-frame/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ every page that production publishes. See the
A child WordPress frame cannot use an existing parent API connection. The root
HTTP server never serves scoped WordPress responses.
- Public scripts, PHP WASM, and WordPress downloads use release URLs, which both
hosts serve. The app and WordPress hosts each register the root `/sw.js` loader,
which imports that release's worker; it chooses its role by origin.
hosts serve. The app and WordPress hosts each register the root `/sw.js` worker,
which chooses its role by origin.
The root keeps its existing on-demand asset cache, shared by every PHP worker.
Eager offline prefetch is disabled. Root-origin scoped subresource requests return 404
for sandbox sites. Each runtime explicitly rejects its app-origin HTTP route,
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/website/playwright/wait-for-edge.mts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ export async function waitForEdge(
function servesRelease(text: string, release: string, baseline?: string) {
return release === 'trunk'
? text === baseline
: text.includes(`import "/releases/${release}/sw.js";`);
: text.includes(`"/releases/${release}/"`);
}
12 changes: 6 additions & 6 deletions packages/playground/website/playwright/wait-for-edge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ afterEach(() => {
});

// Contract: readiness requires a real manifest result and both successful workers.
// Error pages also lack release imports, so status handling can independently
// Error pages also lack release paths, so status handling can independently
// regress from body matching and incorrectly finish a rollback rehearsal.
it.each([429, 500, 503])(
'retries HTTP %s instead of declaring the baseline ready',
Expand Down Expand Up @@ -82,16 +82,16 @@ it.each(['app', 'WordPress'])(
}
);

it('waits until both worker loaders and the manifest name the new release', async () => {
it('waits until both workers and the manifest name the new release', async () => {
queuePoll(
Response.json({ release: 'B' }),
new Response('import "/releases/A/sw.js";'),
new Response('import "/releases/B/sw.js";')
new Response('const base = "/releases/A/";'),
new Response('const base = "/releases/B/";')
);
queuePoll(
Response.json({ release: 'B' }),
new Response('import "/releases/B/sw.js";'),
new Response('import "/releases/B/sw.js";')
new Response('const base = "/releases/B/";'),
new Response('const base = "/releases/B/";')
);
let finished = false;
const ready = waitForEdge(appOrigin, wordPressOrigin, 'B').then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ for (const assetBase of ['/releases/next-release/', '/assets/']) {
'<!doctype html><title>App worker upgrade</title>'
);
} else if (request.url === '/sw.js') {
response.setHeader('Content-Type', 'text/javascript');
response.end(
`import ${JSON.stringify(activeRelease + 'sw.js')};`
);
} else if (
request.url === releaseA + 'sw.js' ||
request.url === releaseB + 'sw.js'
) {
response.setHeader('Content-Type', 'text/javascript');
response.end(
worker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
// eslint-disable-next-line @nx/enforce-module-boundaries
import { getWordPressBridgePath } from '../../../remote/src/lib/wordpress-bridge-path';

// These tests replace the same root worker loader while exercising upgrades.
// These tests replace the same root worker while exercising upgrades.
test.describe.configure({ mode: 'serial' });

// Both hostnames serve the installed web root, including the root /sw.js loader.
// Both hostnames serve the installed web root, including the root /sw.js worker.
const webRoot = resolve(
__dirname,
'../../../../../dist/packages/playground/website-preview'
Expand Down
Loading