Commit 2ff2e9e1 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Update _next/data URL handling in serverless-loader (#10261)

Co-authored-by: 's avatarJoe Haddad <timer150@gmail.com>
parent f143ca63
......@@ -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(
{
......
......@@ -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)
......@@ -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
},
......
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