Skip to content

[Website] Serve the active service worker directly at /sw.js - #4656

Closed
erseco wants to merge 2 commits into
WordPress:trunkfrom
erseco:hotfix/chrome-service-worker-startup
Closed

erseco wants to merge 2 commits into
WordPress:trunkfrom
erseco:hotfix/chrome-service-worker-startup

Conversation

@erseco

@erseco erseco commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Addresses the clean-profile Chrome failure in #4625. Thanks to @rafark for the HAR. The old cached bridge asset failure is tracked separately in #4648.

Chrome receives the root worker successfully. Loading it makes a second request for the same release’s worker module. The shared HAR records HTTP 403 with a text/html response for that import. In a fresh headed Chrome 157.0.8103.79 profile I reproduced the registration failure on the public homepage. Headless Chrome on the same machine loaded both modules and booted WordPress. The hosting rule responsible for the response is still unknown.

The installer now copies the compiled worker to the existing root registration URL on both hosts, so registration needs no second module request. The worker has no relative imports and uses absolute /releases/<id>/ asset URLs, so serving the same bytes at /sw.js keeps its self.location checks, cache names and type: 'module' registration unchanged. Release assets retain their versioned URLs. Installation and rollback use the existing root-file inventory.

check-deployment.sh waits until /sw.js names the active release prefix. Both the copied worker and the older import loader match, so a rollback to a release installed before this change still passes the check. Rolling back to such a release restores the loader and with it the Chrome failure.

Verification

  • Local Playwright A/B with fresh Chrome contexts and the real production bundle. With the release-module request returning 403, the import loader failed registration. Serving the worker bundle directly at the root activated it under the same conditions.
  • Installer contract (test-router.mjs) failed before the fix (root contained the import) and passes after it, including backup and rollback.
  • check-deployment.sh against a local server with three /sw.js layouts: copied worker and old loader pass; another release's worker fails after the wait.
  • wait-for-edge spec, PHP and shell syntax checks pass.
  • The app-worker upgrade e2e fixture now serves the worker directly at /sw.js; it needs the built website-preview, so it runs in CI.

This changes the worker delivery path only. The exact edge rule and behavior after a production deployment have not been verified.

Summary by CodeRabbit

  • Updates
    • The root /sw.js now serves the active release’s service worker directly instead of loading a separate release worker.
    • Existing registrations on both the app and WordPress hosts update to the active worker, which selects its role based on the host.
    • Deployment checks and release-readiness tests now confirm that the worker and release paths match the active release.
    • Updated deployment and migration guidance to reflect the service-worker behavior.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The deployment now copies the active release’s service worker to root /sw.js instead of generating a wrapper. Deployment checks, readiness polling, tests, and documentation identify or compare the root worker as the active worker.

Changes: Root service worker deployment

Layer / File(s) Summary
Install the release worker at the root
packages/playground/website-deployment/apply-update.php, packages/playground/website-deployment/wordpress-frame/test-router.mjs
Activation uses the release’s sw.js as root sw.js. Tests check the installed and backed-up worker content.
Verify the active release worker
packages/playground/website-deployment/check-deployment.sh, packages/playground/website/playwright/wait-for-edge.mts, packages/playground/website/playwright/wait-for-edge.spec.ts, packages/playground/website/playwright/wordpress-frame/app-worker-upgrade.spec.ts
Deployment and readiness checks compare release paths in root workers. Test fixtures serve built worker content and test readiness across differing and matching release paths.
Describe root worker behavior
AGENTS.md, packages/playground/website-deployment/README.md, packages/playground/remote/src/lib/boot-playground-remote.ts, packages/playground/remote/src/lib/wordpress-bridge.ts, packages/playground/website-deployment/wordpress-frame/README.md, packages/playground/website/bin/wordpress-frame/README.md, packages/playground/website/playwright/wordpress-frame/wordpress-bridge-upgrade.spec.ts
Comments and documentation describe /sw.js as the active worker. They also document registration behavior and deployment cache purges.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: brandonpayton, adamziel

Merge Risk: Minimal · up to 44f46

The change deploys the active service worker directly at /sw.js instead of an import loader, avoiding the second request that failed in clean-profile Chrome. No concrete merge-blocking defect was established. The author notes that behavior after production deployment has not been verified, so confirm /sw.js after the first deploy.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "[Website] Serve the active service worker directly at /sw.js" matches the main change in the changeset. The PR stops serving a root /sw.js loader that imports a release-specific worker. Ins…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "[Website] Serve the active service worker directly at /sw.js" matches the main change in the changeset. The PR stops serving a root /sw.js loader that imports a release-specific worker. Instead, the installer copies the compiled worker to the root /sw.js. The changed files cover the installer (apply-update.php), the deployment check (check-deployment.sh), the docs, the tests, and the comments. The title names the primary behavior change and the affected component. It is specific and does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 560131e9-6911-4e3a-81a8-312030c45ea9
Commits

Reviewing files that changed from the base of the PR and between ec63386 and 44f46f8.

Files selected for processing: 7

  • AGENTS.md
  • packages/playground/remote/src/lib/wordpress-bridge.ts
  • packages/playground/website-deployment/apply-update.php
  • packages/playground/website-deployment/check-deployment.sh
  • packages/playground/website/playwright/wait-for-edge.spec.ts
  • packages/playground/website/playwright/wordpress-frame/app-worker-upgrade.spec.ts
  • packages/playground/website/playwright/wordpress-frame/wordpress-bridge-upgrade.spec.ts
Files with no reviewable changes: 1

  • packages/playground/website/playwright/wordpress-frame/app-worker-upgrade.spec.ts
Files skipped from review as they are similar to previous changes: 3

  • packages/playground/remote/src/lib/wordpress-bridge.ts
  • packages/playground/website/playwright/wait-for-edge.spec.ts
  • packages/playground/website/playwright/wordpress-frame/wordpress-bridge-upgrade.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

…d worker

check-deployment.sh now matches the release prefix, so a rollback to a
pre-copy release still passes, and clears the response body before each
request. The app-worker upgrade fixture serves the worker at /sw.js like
the deployment does. Keep sw.js in its original apply-update.php slot and
update comments that still described the loader.
@brandonpayton

Copy link
Copy Markdown
Member

@erseco thank you for sending this patch. It was a good workaround, and I was about to merge it when I received notice that the issue should be resolved now.

Is Playground loading for you?

@erseco

erseco commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @brandonpayton yes, is working right now! I suppose you can discard this PR :)

@brandonpayton

Copy link
Copy Markdown
Member

Hi @brandonpayton yes, is working right now! I suppose you can discard this PR :)

Yeah, I think I will go ahead and close it. Thank you again for the PR. It was timely and a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants