fix: default relative canonical url should not contain search (#63843)
### What Strip the search query for the `urlPathname` passed down to metadata handling. ### Why This is because the `urlPathname` from `staticGenerationStore` contains query, so it will contain `?rsc` query for client navigation, which lead to the relative path canonical url (e.g. `./`) will have the search query along with it. This PR is to remove that and make sure always uses pathname. Reported by @pacocoursey Closes NEXT-2963
This commit is contained in:
parent
c116da32de
commit
488984cc03
3 changed files with 20 additions and 2 deletions
|
@ -58,7 +58,8 @@ export function createMetadataComponents({
|
|||
) => ParsedUrlQuery
|
||||
}): [React.ComponentType, React.ComponentType] {
|
||||
const metadataContext = {
|
||||
pathname,
|
||||
// Make sure the pathname without query string
|
||||
pathname: pathname.split('?')[0],
|
||||
trailingSlash,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export default function Page() {
|
||||
return 'alternate'
|
||||
return <p id="alternates">alternate</p>
|
||||
}
|
||||
|
||||
export async function generateMetadata(props, parentResolvingMetadata) {
|
||||
|
|
|
@ -352,6 +352,23 @@ createNextDescribe(
|
|||
})
|
||||
})
|
||||
|
||||
it('should not contain query in canonical url after client navigation', async () => {
|
||||
const browser = await next.browser('/')
|
||||
await browser.waitForElementByCss('p#index')
|
||||
await browser.eval(`next.router.push('/alternates')`)
|
||||
// wait for /alternates page is loaded
|
||||
await browser.waitForElementByCss('p#alternates')
|
||||
|
||||
const matchDom = createDomMatcher(browser)
|
||||
await matchDom('link', 'rel="canonical"', {
|
||||
href: 'https://example.com/alternates',
|
||||
})
|
||||
await matchDom('link', 'title="js title"', {
|
||||
type: 'application/rss+xml',
|
||||
href: 'https://example.com/blog/js.rss',
|
||||
})
|
||||
})
|
||||
|
||||
it('should support robots tags', async () => {
|
||||
const $ = await next.render$('/robots')
|
||||
const matchMultiDom = createMultiHtmlMatcher($)
|
||||
|
|
Loading…
Reference in a new issue