Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts landing-page redirection to use relative paths so Safari’s service-worker Response.redirect() workaround preserves the scoped URL prefix during resolution.
Changes:
- Adds detailed rationale/docs for why relative landing-page paths are required for scoped service-worker routing.
- Replaces
pathToInternalUrl()usage with a simple absolute-to-relative path rewrite (/foo→./foo) before redirecting via the intermediate handler.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…L resolution in the service worker
93652ca to
79bc32a
Compare
brandonpayton
approved these changes
Mar 10, 2026
Member
brandonpayton
left a comment
There was a problem hiding this comment.
This looks great. Thank you, @mho22!
Updated comments to clarify the purpose of awaiting response headers for cookie storage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation for the change, related issues
#3361 introduced streamed PHP responses in the service worker. This changed the cookie store population from synchronous (awaited via
PHPResponse.fromStreamedResponse()) to a floating.then()that could resolve after the next request arrived. This causedplayground_auto_loginto redirect infinitely on Safari because theplayground_auto_login_already_happenedcookie was never stored in time.Response.redirect()dropsSet-Cookieheaders, and the internal cookie store was the only mechanism preserving them across requests.A secondary issue was that
Response.redirect(new URL('/wp-admin/', scopedUrl))resolves absolute paths against the origin, stripping the/scope:…/prefix.cc @bgrgicak
Implementation details
php-request-handler.ts: Replace the floating.then()with await response.headers before returning fromrequestStreamed(), ensuring the cookie store is populated before the next request can arrive. Headers are available as soon as PHP flushes them, well before the body finishes streaming, so this does not hurt throughput.utils.ts: Re-scope the Location URL before callingResponse.redirect(). If the resolved URL lacks the/scope:…/prefix, add it back usingsetURLScope.Testing Instructions (or ideally a Blueprint)
run
npm run devand go tohttp://127.0.0.1:5400/website-server/on safariIt will crash on
trunkand run correctly from this branch.