Skip to content

Commit

Permalink
Update _next/data URL handling in serverless-loader (#10261)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Haddad <timer150@gmail.com>
  • Loading branch information
ijjk and Timer committed Jan 25, 2020
1 parent f143ca6 commit 2ff2e9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/next/build/webpack/loaders/next-serverless-loader.ts
Expand Up @@ -216,13 +216,14 @@ const nextServerlessLoader: loader.Loader = function() {
}
let _nextData = false
if (req.url.match(/_next\\/data/)) {
const parsedUrl = handleRewrites(parse(req.url, true))
if (parsedUrl.pathname.match(/_next\\/data/)) {
_nextData = true
req.url = req.url
parsedUrl.pathname = parsedUrl.pathname
.replace(new RegExp('/_next/data/${escapedBuildId}/'), '/')
.replace(/\\.json$/, '')
}
const parsedUrl = handleRewrites(parse(req.url, true))
const renderOpts = Object.assign(
{
Expand Down
12 changes: 11 additions & 1 deletion test/integration/prerender/test/index.test.js
Expand Up @@ -265,6 +265,16 @@ const runTests = (dev = false) => {
expect(JSON.parse(params)).toEqual({})
})

it('should not supply query values to params in /_next/data request', async () => {
const data = JSON.parse(
await renderViaHTTP(
appPort,
`/_next/data/${buildId}/something.json?hello=world`
)
)
expect(data.pageProps.params).toEqual({})
})

it('should not supply query values to params or useRouter dynamic page SSR', async () => {
const html = await renderViaHTTP(appPort, '/blog/post-1?hello=world')
const $ = cheerio.load(html)
Expand Down Expand Up @@ -580,7 +590,7 @@ describe('SPR Prerender', () => {
await nextBuild(appDir)
stderr = ''
appPort = await findPort()
app = nextStart(appDir, appPort, {
app = await nextStart(appDir, appPort, {
onStderr: msg => {
stderr += msg
},
Expand Down

0 comments on commit 2ff2e9e

Please sign in to comment.