-
Notifications
You must be signed in to change notification settings - Fork 89
test: add locale assertions for middleware handling #2984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
test: add locale assertions for middleware handling #2984
Conversation
📊 Package size report No changes
Unchanged files
🤖 This report was automatically generated by pkg-size-action |
const rewriteUrl = new URL( | ||
url.pathname.replace('/link/rewrite-me', '/link/rewrite-target'), | ||
url, | ||
) | ||
return NextResponse.rewrite(rewriteUrl, { | ||
// use NextUrl to rewrite the URL as it does preserve the locale | ||
url.pathname = url.pathname.replace('/link/rewrite-me', '/link/rewrite-target') | ||
return NextResponse.rewrite(url, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: previous rewrite was just losing locale url due to using just NextURL.pathname
to construct new URL
effectively losing locale context in the process.
This change keeps using NextURL
and just mutate pathname
portion of it which preserve locale
context and resulting in working as expected rewrites
@@ -63,11 +63,13 @@ test.describe('json data', () => { | |||
describeLabel: 'NextResponse.next() -> getServerSideProps page', | |||
selector: 'NextResponse.next()#getServerSideProps', | |||
jsonPathMatcher: '/link/next-getserversideprops.json', | |||
assertLocale: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only getServerSideProps
and getStaticProps
even have access to locale and "fully static page" cases just don't have access to it so asserting locale is optional check enabled to cases when locale is even available to check
Description
Tests
You can test this change yourself like so:
Relevant links (GitHub issues, etc.) or a picture of cute animal
#2973
https://linear.app/netlify/issue/FRB-1919/version-5113-doesnt-seem-to-pass-the-correct-locale-anymore-from