Unverified Commit b1ef76df authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix asPath normalizing for non-dynamic pages (#15960)

parent db69e474
...@@ -439,6 +439,9 @@ const nextServerlessLoader: loader.Loader = function () { ...@@ -439,6 +439,9 @@ const nextServerlessLoader: loader.Loader = function () {
// make sure to normalize req.url on Vercel to strip dynamic params // make sure to normalize req.url on Vercel to strip dynamic params
// from the query which are added during routing // from the query which are added during routing
${
pageIsDynamicRoute
? `
if (trustQuery) { if (trustQuery) {
const _parsedUrl = parseUrl(req.url, true) const _parsedUrl = parseUrl(req.url, true)
delete _parsedUrl.search delete _parsedUrl.search
...@@ -448,6 +451,9 @@ const nextServerlessLoader: loader.Loader = function () { ...@@ -448,6 +451,9 @@ const nextServerlessLoader: loader.Loader = function () {
} }
req.url = formatUrl(_parsedUrl) req.url = formatUrl(_parsedUrl)
} }
`
: ''
}
const isFallback = parsedUrl.query.__nextFallback const isFallback = parsedUrl.query.__nextFallback
......
export default function Page(props) { export default function Page(props) {
return <div>about</div> return <div id="content">about</div>
}
export const getServerSideProps = () => {
return {
props: {},
}
} }
...@@ -16,6 +16,8 @@ const server = http.createServer((req, res) => { ...@@ -16,6 +16,8 @@ const server = http.createServer((req, res) => {
const { pathname } = url.parse(req.url) const { pathname } = url.parse(req.url)
switch (pathname) { switch (pathname) {
case '/about':
return render('/about.js')
case '/api/post': case '/api/post':
case '/api/post/hello': case '/api/post/hello':
case '/api/post/hello/world': { case '/api/post/hello/world': {
......
...@@ -370,6 +370,12 @@ describe('Dynamic Optional Routing', () => { ...@@ -370,6 +370,12 @@ describe('Dynamic Optional Routing', () => {
}).then((res) => res.text()) }).then((res) => res.text())
} }
it('should render normal (non-dynamic) page', async () => {
const html = await render('/about')
const $ = cheerio.load(html)
expect($('#content').text()).toBe('about')
})
it('should render top level optional catch-all root', async () => { it('should render top level optional catch-all root', async () => {
const html = await render('/', { optionalName: '' }) const html = await render('/', { optionalName: '' })
const $ = cheerio.load(html) const $ = cheerio.load(html)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment