Skip to content

Commit dabeb51

Browse files
authored
Fix SSG query with experimental-compile (#56680)
Ensures query isn't omitted when using experimental compile mode with SSG pages as it skips the isReady delay that is normally done with prerendering.
1 parent d73b836 commit dabeb51

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

packages/next/src/build/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ export default async function build(
941941
? path.relative(distDir, incrementalCacheHandlerPath)
942942
: undefined,
943943

944-
isExperimentalCompile: true,
944+
isExperimentalCompile: isCompile,
945945
},
946946
},
947947
appDir: dir,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ export default class NextNodeServer extends BaseServer {
688688
return {
689689
components,
690690
query: {
691-
...(components.getStaticProps
691+
...(!this.renderOpts.isExperimentalCompile &&
692+
components.getStaticProps
692693
? ({
693694
amp: query.amp,
694695
__nextDataReq: query.__nextDataReq,

packages/next/src/server/next.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class NextServer {
199199
)).config
200200

201201
// @ts-expect-error internal field
202-
config.experimental.isExperimentalConfig =
202+
config.experimental.isExperimentalCompile =
203203
serializedConfig.experimental.isExperimentalCompile
204204
} catch (_) {
205205
// if distDir is customized we don't know until we

test/e2e/app-dir/app/index.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ createNextDescribe(
1414
: undefined,
1515
},
1616
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
17+
if (process.env.NEXT_EXPERIMENTAL_COMPILE) {
18+
it('should provide query for getStaticProps page correctly', async () => {
19+
const res = await next.fetch('/ssg?hello=world')
20+
expect(res.status).toBe(200)
21+
22+
const $ = cheerio.load(await res.text())
23+
expect(JSON.parse($('#query').text())).toEqual({ hello: 'world' })
24+
})
25+
}
26+
1727
if (isNextStart && !process.env.NEXT_EXPERIMENTAL_COMPILE) {
1828
it('should not have loader generated function for edge runtime', async () => {
1929
expect(

test/e2e/app-dir/app/pages/ssg.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { useRouter } from 'next/router'
2+
3+
export default function Page(props) {
4+
return (
5+
<>
6+
<p>hello from ssg</p>
7+
<p id="query">{JSON.stringify(useRouter().query)}</p>
8+
</>
9+
)
10+
}
11+
12+
export function getStaticProps() {
13+
return {
14+
props: {},
15+
}
16+
}

0 commit comments

Comments
 (0)