Fix publicPath URL duplication when prefix appears as substring#3393
Open
laurakwhit wants to merge 4 commits into
Open
Fix publicPath URL duplication when prefix appears as substring#3393laurakwhit wants to merge 4 commits into
laurakwhit wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
laurakwhit
commented
May 13, 2026
| if rawQuery != "" { | ||
| target += "?" + rawQuery | ||
| } | ||
| return c.Redirect(http.StatusPermanentRedirect, target) |
Collaborator
Author
There was a problem hiding this comment.
Wondering if we should consider changing this to a 307 vs. a 308. Currently, any changes to the public path after rollout will require users to clear cached redirects.
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.
Description & motivation 💭
The substring
/customis short and generic enough to appear inside a URL path other than at position 0 (e.g. asset chunks like/_app/immutable/chunks/custom-XXXXX.js). Any time the middleware saw a request whoseRequestURIcontained/customsomewhere past position 0, it rewrote thereq.URLto just the suffix and threw away the prefix. That mangledURL.Paththen drove the redirect logic inbuildUIIndexHandler.This PRs fixes this by
RequestURI(which middleware doesn't touch) instead of a mix ofRequestURIandURL.PathhasPathPrefix(handles exact paths and sub-paths)route.PublicPathto usemiddleware.RewriteWithConfig{ RegexRules: ... }with an explicitly-anchored pattern (^/custom/(.*?)$) to prevent the substring matchingIt also inlines
resolve()intowithPrefix()so deprecatedbasepath is no longer needed.Note: 308 is cached aggressively by browsers. Once a wrong redirect target is cached, the doubled URL sticks around until cache is cleared.
Screenshots (if applicable) 📸
Design Considerations 🎨
Testing 🧪
How was this tested 👻
Steps for others to test: 🚶🏽♂️🚶🏽♀️
pnpm test src/lib/utilities/route-for-base-path.test.tspnpm test src/lib/utilities/route-for.test.tscd server && go test ./server/route/...Run the following ⬇️
Then go to http://localhost:5252
/customand does not cause an infinite loop/namespacesredirects to/custom/namespacesClear browser cache and then run the following (without a
publicPathset) ⬇️Then go to http://localhost:5252
Checklists
Draft Checklist
Merge Checklist
Issue(s) closed
Docs
Any docs updates needed?