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

Fix RSC link navigation #32303

Merged
merged 5 commits into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/next/client/index.tsx
Expand Up @@ -673,11 +673,9 @@ if (process.env.__NEXT_RSC) {
return Promise.resolve({ body: t.readable })
})()
: (() => {
const search = location.search
const { search, pathname } = location
const flightReqUrl =
location.pathname +
search +
(search ? '&__flight__' : '?__flight__')
pathname + search + (search ? '&' : '?') + '__flight__'
huozhi marked this conversation as resolved.
Show resolved Hide resolved
return fetch(flightReqUrl)
})()
)
Expand Down
4 changes: 3 additions & 1 deletion packages/next/client/page-loader.ts
Expand Up @@ -147,7 +147,9 @@ export default class PageLoader {
const route = normalizeRoute(hrefPathname)

const getHrefForSlug = (path: string) => {
if (rsc) return path + '?__flight__'
if (rsc) {
return path + search + (search ? `&` : '?') + '__flight__'
}

const dataRoute = getAssetPathFromRoute(
removePathTrailingSlash(addLocale(path, locale)),
Expand Down
@@ -1,9 +1,17 @@
import NextLink from 'next/link'
import Link from 'next/link'

export default function Link() {
export default function LinkPage({ router }) {
const { query } = router
const id = parseInt(query.id || '0', 10)
return (
<NextLink href={`/`}>
<a>go home</a>
</NextLink>
<>
<h3 id="query">query:{id}</h3>
<Link href={`/next-api/link?id=${id + 1}`}>
<a id="next_id">next id</a>
</Link>
<Link href={`/`}>
<a>go home</a>
</Link>
</>
)
}
Expand Up @@ -14,6 +14,7 @@ import {
nextBuild as _nextBuild,
nextStart as _nextStart,
renderViaHTTP,
check,
} from 'next-test-utils'

import css from './css'
Expand Down Expand Up @@ -285,12 +286,17 @@ async function runBasicTests(context, env) {
expect(pathNotFoundHTML).toContain('custom-404-page')
})

it('should suspense next/link on server side', async () => {
it('should support next/link', async () => {
const linkHTML = await renderViaHTTP(context.appPort, '/next-api/link')
const $ = cheerio.load(linkHTML)
const linkText = $('div[hidden] > a[href="/"]').text()

expect(linkText).toContain('go home')

const browser = await webdriver(context.appPort, '/next-api/link')
await browser.elementByCss('#next_id').click()
await browser.elementByCss('#next_id').click()
await check(() => browser.waitForElementByCss('#query').text(), /query:2/)
huozhi marked this conversation as resolved.
Show resolved Hide resolved
})

it('should suspense next/image on server side', async () => {
Expand Down