Skip to content
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

Ensure client filter with basePath is correct #60580

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/next/src/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,13 +1319,6 @@ export default class Router implements BaseRouter {
let parsed = parseRelativeUrl(url)
let { pathname, query } = parsed

// if we detected the path as app route during prefetching
// trigger hard navigation
if ((this.components[pathname] as any)?.__appRouter) {
handleHardNavigation({ url: as, router: this })
return new Promise(() => {})
}

// The build manifest needs to be loaded before auto-static dynamic pages
// get their query parameters to allow ensuring they can be parsed properly
// when rewritten to
Expand Down Expand Up @@ -1366,6 +1359,13 @@ export default class Router implements BaseRouter {
let route = removeTrailingSlash(pathname)
const parsedAsPathname = as.startsWith('/') && parseRelativeUrl(as).pathname

// if we detected the path as app route during prefetching
// trigger hard navigation
if ((this.components[pathname] as any)?.__appRouter) {
handleHardNavigation({ url: as, router: this })
return new Promise(() => {})
}

const isMiddlewareRewrite = !!(
parsedAsPathname &&
route !== parsedAsPathname &&
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/app-dir/app-basepath/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ createNextDescribe(
},
},
({ next }) => {
it('should successfully hard navigate from pages -> app', async () => {
const browser = await next.browser('/base/pages-path')
await browser.elementByCss('#to-another').click()
await browser.waitForElementByCss('#page-2')
})

it('should support `basePath`', async () => {
const html = await next.render('/base')
expect(html).toContain('<h1>Test Page</h1>')
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/app-dir/app-basepath/pages/pages-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link'

export default function Page() {
return (
<>
<p>pages-path</p>
<Link href="/another" id="to-another">
to /another
</Link>
</>
)
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ createNextDescribe(
})
}

it('should successfully hard navigate from pages -> app', async () => {
const browser = await next.browser('/')

await browser.elementByCss('a').click()
await browser.waitForElementByCss('#from-dashboard')
})

it('should encode chunk path correctly', async () => {
await next.fetch('/dynamic-client/first/second')
const browser = await next.browser('/')
Expand Down
Loading