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

Fix SSG query with experimental-compile #56680

Merged
merged 3 commits into from Oct 11, 2023
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
2 changes: 1 addition & 1 deletion packages/next/src/build/index.ts
Expand Up @@ -941,7 +941,7 @@ export default async function build(
? path.relative(distDir, incrementalCacheHandlerPath)
: undefined,

isExperimentalCompile: true,
isExperimentalCompile: isCompile,
},
},
appDir: dir,
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/server/next-server.ts
Expand Up @@ -688,7 +688,8 @@ export default class NextNodeServer extends BaseServer {
return {
components,
query: {
...(components.getStaticProps
...(!this.renderOpts.isExperimentalCompile &&
components.getStaticProps
? ({
amp: query.amp,
__nextDataReq: query.__nextDataReq,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/next.ts
Expand Up @@ -199,7 +199,7 @@ export class NextServer {
)).config

// @ts-expect-error internal field
config.experimental.isExperimentalConfig =
config.experimental.isExperimentalCompile =
serializedConfig.experimental.isExperimentalCompile
} catch (_) {
// if distDir is customized we don't know until we
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/app-dir/app/index.test.ts
Expand Up @@ -14,6 +14,16 @@ createNextDescribe(
: undefined,
},
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
if (process.env.NEXT_EXPERIMENTAL_COMPILE) {
it('should provide query for getStaticProps page correctly', async () => {
const res = await next.fetch('/ssg?hello=world')
expect(res.status).toBe(200)

const $ = cheerio.load(await res.text())
expect(JSON.parse($('#query').text())).toEqual({ hello: 'world' })
})
}

if (isNextStart && !process.env.NEXT_EXPERIMENTAL_COMPILE) {
it('should not have loader generated function for edge runtime', async () => {
expect(
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/app-dir/app/pages/ssg.js
@@ -0,0 +1,16 @@
import { useRouter } from 'next/router'

export default function Page(props) {
return (
<>
<p>hello from ssg</p>
<p id="query">{JSON.stringify(useRouter().query)}</p>
</>
)
}

export function getStaticProps() {
return {
props: {},
}
}