Skip to content

Commit

Permalink
Merge branch 'canary' into improve-sentry-example-ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Aug 7, 2020
2 parents 9a9190e + b1ef76d commit 94e5c96
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
18 changes: 12 additions & 6 deletions packages/next/build/webpack/loaders/next-serverless-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,20 @@ const nextServerlessLoader: loader.Loader = function () {
// make sure to normalize req.url on Vercel to strip dynamic params
// from the query which are added during routing
if (trustQuery) {
const _parsedUrl = parseUrl(req.url, true)
delete _parsedUrl.search
${
pageIsDynamicRoute
? `
if (trustQuery) {
const _parsedUrl = parseUrl(req.url, true)
delete _parsedUrl.search
for (const param of Object.keys(defaultRouteRegex.groups)) {
delete _parsedUrl.query[param]
for (const param of Object.keys(defaultRouteRegex.groups)) {
delete _parsedUrl.query[param]
}
req.url = formatUrl(_parsedUrl)
}
req.url = formatUrl(_parsedUrl)
`
: ''
}
const isFallback = parsedUrl.query.__nextFallback
Expand Down
8 changes: 7 additions & 1 deletion test/integration/dynamic-optional-routing/pages/about.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export default function Page(props) {
return <div>about</div>
return <div id="content">about</div>
}

export const getServerSideProps = () => {
return {
props: {},
}
}
2 changes: 2 additions & 0 deletions test/integration/dynamic-optional-routing/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const server = http.createServer((req, res) => {
const { pathname } = url.parse(req.url)

switch (pathname) {
case '/about':
return render('/about.js')
case '/api/post':
case '/api/post/hello':
case '/api/post/hello/world': {
Expand Down
6 changes: 6 additions & 0 deletions test/integration/dynamic-optional-routing/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ describe('Dynamic Optional Routing', () => {
}).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 () => {
const html = await render('/', { optionalName: '' })
const $ = cheerio.load(html)
Expand Down

0 comments on commit 94e5c96

Please sign in to comment.