Skip to content

[Website] Cache public Playground 404 responses at the edge - #4655

Open
brandonpayton wants to merge 4 commits into
trunkfrom
cache-public-404s
Open

brandonpayton wants to merge 4 commits into
trunkfrom
cache-public-404s

Conversation

@brandonpayton

@brandonpayton brandonpayton commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Mark ordinary router-generated GET and HEAD 404s for edge caching on the app and WordPress sandbox hosts. The origin sends A8C-Edge-Cache: cache and requests a 60-second shared-cache lifetime with immediate browser revalidation.

Keep no-store on PHP endpoint errors, scoped navigation fallbacks, and other errors.

WordPress at a scoped URL runs in the browser. Safari can open a scoped link in a new tab outside the sandbox service worker's control. If that top-level GET reaches WP Cloud, the sandbox redirects it to the app. The app serves a wrapper that recreates the WordPress iframe and reconnects it to the running site. A scoped iframe request that reaches the server receives a 404. Keep that 404 uncached so the edge can still route a later top-level GET to the wrapper. This preserves the existing Safari new-tab fallback.

WP Cloud and deployment

The installer publishes the complete release directory and activates the root files before requesting a full-domain purge for each hostname. The WP Cloud API schema documents that the domain-specific purge clears the whole domain when purge_uris is omitted. The existing deployment check already accounts for propagation delay by waiting for the new root loaders on both hosts.

A cached 404 can still be served while that purge propagates. An origin request started before publication could also finish after a purge and refill the cache if WP Cloud allows in-flight responses to be stored then. The public API does not specify that behavior. The Edge Cache docs document the opt-out header and the x-ac hit signal, but leave PHP-generated 404 eligibility and the effect of s-maxage unspecified. WP Cloud documents that it can supply its own cache headers for cached responses. The requested 60 seconds should therefore be treated as an origin directive until verified on WP Cloud. HTTP and security headers

Before activation

After publishing the versioned files, the installer performs GET requests for the versioned worker on both hosts, the remote page on the app host, and the WordPress bridge on the sandbox host. If any return 404, it requests a hostname-specific purge of only those release URLs and waits for HTTP 200. A failed probe or purge leaves the previous release active. The existing full-domain purges still run after activation.

The router fixture verifies that a targeted purge runs while the root worker still points to the previous release and that an unsuccessful probe leaves the root worker in place. A live staging run remains necessary to verify the targeted purge against WP Cloud and observe propagation.

Verification

  • Passed the PHP deployment tests, PHP syntax check, and the Nx router and static-file range targets.
  • On WP Cloud staging, request the same missing URL without cookies on each host until it yields a 404 with x-ac: … HIT. Then publish a file at that URL through the normal deployment and check that each host serves 200 after the purge. This would verify both eligibility and invalidation on WP Cloud.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected caching for missing-page responses. Eligible GET and HEAD requests can be cached briefly, while POST requests and other error responses are not cached.
    • Preserved no-cache behavior for iframe fallback errors and scoped sandbox requests.
  • Deployment
    • Required release assets are checked on both hosts before activation. Missing assets trigger targeted purges and rechecks; other failed checks or assets that remain unavailable prevent activation, leaving the previous release active.
    • After successful checks and activation, both domains are purged.

@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 change updates cache headers for eligible missing-path responses. The deployment installer checks versioned release URLs before activation, requests targeted purges after 404 responses, and keeps the previous release active if checks fail.

Changes: 404 response caching

Layer / File(s) Summary
Set headers for eligible 404 responses
packages/playground/website-deployment/custom-redirects-lib.php, packages/playground/website-deployment/wordpress-frame/test-router.mjs
Marked GET and HEAD 404 responses receive shared-cache headers. Other error responses remain uncached. Tests cover both hosts, GET/HEAD/POST methods, and scoped iframe responses.

Release verification

Layer / File(s) Summary
Check release assets before activation
packages/playground/website-deployment/apply-update.sh, packages/playground/website-deployment/wordpress-frame/test-router.mjs, packages/playground/website-deployment/README.md, AGENTS.md
The installer checks release files and versioned URLs on both hosts. It requests targeted purges and retries when a URL returns 404. Other non-200 statuses or a 60-second timeout prevent activation. Tests cover blocked and stale assets and targeted purge details. The deployment guidance describes the checks and activation sequence.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Installer
  participant Edge
  participant PurgeAPI
  Installer->>Edge: Check versioned release URL
  Edge-->>Installer: Return HTTP status
  Installer->>PurgeAPI: Purge affected URLs after 404
  Installer->>Edge: Retry release URL checks
  Edge-->>Installer: Return HTTP 200 or failure status
Loading

Possibly related PRs

Suggested labels: [Aspect] Website

Suggested reviewers: adamziel

Merge Risk: Minimal · up to 544a4

The change lets the edge cache ordinary Playground 404 responses for 60 seconds. Scoped iframe 404s and endpoint errors stay uncached, and a deployment that fails its pre-activation checks leaves the previous release in place. I found no merge-blocking risk; confirm the edge-cache behavior on WP Cloud staging after deployment.

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] Cache public Playground 404 responses at the edge" matches the main change. The objectives say the PR marks ordinary router-generated GET and HEAD 404s on the app and WordPress sa…
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] Cache public Playground 404 responses at the edge" matches the main change. The objectives say the PR marks ordinary router-generated GET and HEAD 404s on the app and WordPress sandbox hosts for edge caching. The changeset's summaries show the same: 404 cache headers are deferred and cacheable 404s get edge-cache and s-maxage headers. The title does not mention the deployment changes (root-file switch checks, targeted purges), but those support the main change and are not the headline.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • 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: a1490f8e-7f9e-4a15-b306-326afab73f00
Commits

Reviewing files that changed from the base of the PR and between d6b2d55 and 544a430.

Files selected for processing: 1

  • packages/playground/website-deployment/custom-redirects-lib.php
Files skipped from review as they are similar to previous changes: 1

  • packages/playground/website-deployment/custom-redirects-lib.php

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

@github-actions github-actions Bot added the [Type] Documentation Improvements or additions to documentation label Nov 19, 2026

This branch has not been deployed

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

Labels

[Type] Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant