Skip to content

Commit 93424b6

Browse files
authored
Use correct default for query (#5851)
1 parent 6b7864e commit 93424b6

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

packages/next-server/server/next-server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export default class Server {
205205
return sendHTML(req, res, html, {generateEtags})
206206
}
207207

208-
public async render (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery, parsedUrl: UrlWithParsedQuery): Promise<void> {
208+
public async render (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}, parsedUrl?: UrlWithParsedQuery): Promise<void> {
209209
const url: any = req.url
210210
if (isInternalUrl(url)) {
211211
return this.handleRequest(req, res, parsedUrl)
@@ -227,7 +227,7 @@ export default class Server {
227227
return this.sendHTML(req, res, html)
228228
}
229229

230-
public async renderToHTML (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery): Promise<string|null> {
230+
public async renderToHTML (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise<string|null> {
231231
try {
232232
// To make sure the try/catch is executed
233233
const html = await renderToHTML(req, res, pathname, query, this.renderOpts)
@@ -243,13 +243,13 @@ export default class Server {
243243
}
244244
}
245245

246-
public async renderError (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery): Promise<void> {
246+
public async renderError (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}): Promise<void> {
247247
res.setHeader('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate')
248248
const html = await this.renderErrorToHTML(err, req, res, pathname, query)
249249
return this.sendHTML(req, res, html)
250250
}
251251

252-
public async renderErrorToHTML (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery) {
252+
public async renderErrorToHTML (err: Error|null, req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery = {}) {
253253
return renderErrorToHTML(err, req, res, pathname, query, this.renderOpts)
254254
}
255255

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => 'test'

test/integration/custom-server/server.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const handleNextRequests = app.getRequestHandler()
1010

1111
app.prepare().then(() => {
1212
const server = new http.Server((req, res) => {
13+
if (req.url === '/no-query') {
14+
return app.render(req, res, '/no-query')
15+
}
16+
1317
if (/setAssetPrefix/.test(req.url)) {
1418
app.setAssetPrefix(`http://127.0.0.1:${port}`)
1519
} else if (/setEmptyAssetPrefix/.test(req.url)) {

test/integration/custom-server/test/index.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ describe('Custom Server', () => {
3737
beforeAll(() => startServer())
3838
afterAll(() => killApp(server))
3939

40+
it('should handle render with undefined query', async () => {
41+
expect(await renderViaHTTP(appPort, '/no-query')).toMatch(/"query":/)
42+
})
43+
4044
it('should set the assetPrefix dynamically', async () => {
4145
const normalUsage = await renderViaHTTP(appPort, '/asset')
4246
expect(normalUsage).not.toMatch(/127\.0\.0\.1/)

0 commit comments

Comments
 (0)