Skip to content

Commit 2ff2e9e

Browse files
ijjkTimer
andcommitted
Update _next/data URL handling in serverless-loader (vercel#10261)
Co-authored-by: Joe Haddad <timer150@gmail.com>
1 parent f143ca6 commit 2ff2e9e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/next/build/webpack/loaders/next-serverless-loader.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,14 @@ const nextServerlessLoader: loader.Loader = function() {
216216
}
217217
let _nextData = false
218218
219-
if (req.url.match(/_next\\/data/)) {
219+
const parsedUrl = handleRewrites(parse(req.url, true))
220+
221+
if (parsedUrl.pathname.match(/_next\\/data/)) {
220222
_nextData = true
221-
req.url = req.url
223+
parsedUrl.pathname = parsedUrl.pathname
222224
.replace(new RegExp('/_next/data/${escapedBuildId}/'), '/')
223225
.replace(/\\.json$/, '')
224226
}
225-
const parsedUrl = handleRewrites(parse(req.url, true))
226227
227228
const renderOpts = Object.assign(
228229
{

test/integration/prerender/test/index.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ const runTests = (dev = false) => {
265265
expect(JSON.parse(params)).toEqual({})
266266
})
267267

268+
it('should not supply query values to params in /_next/data request', async () => {
269+
const data = JSON.parse(
270+
await renderViaHTTP(
271+
appPort,
272+
`/_next/data/${buildId}/something.json?hello=world`
273+
)
274+
)
275+
expect(data.pageProps.params).toEqual({})
276+
})
277+
268278
it('should not supply query values to params or useRouter dynamic page SSR', async () => {
269279
const html = await renderViaHTTP(appPort, '/blog/post-1?hello=world')
270280
const $ = cheerio.load(html)
@@ -580,7 +590,7 @@ describe('SPR Prerender', () => {
580590
await nextBuild(appDir)
581591
stderr = ''
582592
appPort = await findPort()
583-
app = nextStart(appDir, appPort, {
593+
app = await nextStart(appDir, appPort, {
584594
onStderr: msg => {
585595
stderr += msg
586596
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy