feat(client-redirects-plugin): support fully qualified urls and querystring/hash in destination/to url #9171
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
Fix #6845
The client redirect plugins should allow redirecting to:
The validation has been related to any string, because if we support full/absolute/relative almost all strings are valid candidates, and creating a robust validator for that is quite hard.
Historically the redirects forwarded the
?search#anchor
from the redirect source. Now if the destination/target URL has a qs/hash, we don't do this forwarding anymore and consider the destination URL provided by the user is in its final form. We could improve that logic later if needed but that seems good enough for now.Note: I'm not 100% sure this is perfectly retro-compatible, some difficult-to-detect subtle behavior could have changed a bit, so we won't backport this PR and keep it for Docusaurus v3.
Test Plan
Unit tests + dogfood
Test links
Local redirects
https://deploy-preview-9171--docusaurus-2.netlify.app/home/ => to local home
https://deploy-preview-9171--docusaurus-2.netlify.app/home/?q=1#hash => to local home with q/h forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/qs => to local home with qs
https://deploy-preview-9171--docusaurus-2.netlify.app/home/qs?q=1#hash => to local home with qs and no forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/anchor => to local home with anchor
https://deploy-preview-9171--docusaurus-2.netlify.app/home/anchor?q=1#hash => to local home with anchor and no forwarding
Fully qualified URL redirects:
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute => to prod home
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute?q=1#hash => to prod home with q/h forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/qs => to prod home with qs
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/qs?q=1#hash => to prod home with qs and no forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/anchor => to prod home with anchor
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/anchor?q=1#hash => to prod home with anchor and no forwarding