Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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({})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query should be empty too, right? Not just params.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query isn't passed in getStaticProps. We check it's not supplied during rendering in useRouter in the above test

})

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