Skip to content

Commit f4d4487

Browse files
committed
Merge remote-tracking branch 'upstream/canary' into unflag/notFound
2 parents 75122e3 + 2972c06 commit f4d4487

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

packages/next/next-server/server/render.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ export async function renderToHTML(
636636
throw new Error(invalidKeysMsg('getStaticProps', invalidKeys))
637637
}
638638

639-
if (data.notFound) {
639+
if ('notFound' in data && data.notFound) {
640640
if (pathname === '/404') {
641641
throw new Error(
642642
`The /404 page can not return notFound in "getStaticProps", please remove it to continue!`
@@ -649,6 +649,7 @@ export async function renderToHTML(
649649
}
650650

651651
if (
652+
'unstable_redirect' in data &&
652653
data.unstable_redirect &&
653654
typeof data.unstable_redirect === 'object'
654655
) {
@@ -662,7 +663,7 @@ export async function renderToHTML(
662663
}
663664

664665
if (isDataReq) {
665-
data.props = {
666+
;(data as any).props = {
666667
__N_REDIRECT: data.unstable_redirect.destination,
667668
}
668669
} else {
@@ -673,15 +674,15 @@ export async function renderToHTML(
673674

674675
if (
675676
(dev || isBuildTimeSSG) &&
676-
!isSerializableProps(pathname, 'getStaticProps', data.props)
677+
!isSerializableProps(pathname, 'getStaticProps', (data as any).props)
677678
) {
678679
// this fn should throw an error instead of ever returning `false`
679680
throw new Error(
680681
'invariant: getStaticProps did not return valid props. Please report this.'
681682
)
682683
}
683684

684-
if (typeof data.revalidate === 'number') {
685+
if ('revalidate' in data && typeof data.revalidate === 'number') {
685686
if (!Number.isInteger(data.revalidate)) {
686687
throw new Error(
687688
`A page's revalidate option must be seconds expressed as a natural number. Mixed numbers, such as '${data.revalidate}', cannot be used.` +
@@ -702,20 +703,25 @@ export async function renderToHTML(
702703
`\nTo only run getStaticProps at build-time and not revalidate at runtime, you can set \`revalidate\` to \`false\`!`
703704
)
704705
}
705-
} else if (data.revalidate === true) {
706+
} else if ('revalidate' in data && data.revalidate === true) {
706707
// When enabled, revalidate after 1 second. This value is optimal for
707708
// the most up-to-date page possible, but without a 1-to-1
708709
// request-refresh ratio.
709710
data.revalidate = 1
710711
} else {
711712
// By default, we never revalidate.
712-
data.revalidate = false
713+
;(data as any).revalidate = false
713714
}
714715

715-
props.pageProps = Object.assign({}, props.pageProps, data.props)
716+
props.pageProps = Object.assign(
717+
{},
718+
props.pageProps,
719+
'props' in data ? data.props : undefined
720+
)
716721
// pass up revalidate and props for export
717722
// TODO: change this to a different passing mechanism
718-
;(renderOpts as any).revalidate = data.revalidate
723+
;(renderOpts as any).revalidate =
724+
'revalidate' in data ? data.revalidate : undefined
719725
;(renderOpts as any).pageData = props
720726
}
721727

packages/next/types/index.d.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ export type GetStaticPropsContext<Q extends ParsedUrlQuery = ParsedUrlQuery> = {
8585
locales?: string[]
8686
}
8787

88-
export type GetStaticPropsResult<P> = {
89-
props?: P
90-
revalidate?: number | boolean
91-
unstable_redirect?: Redirect
92-
notFound?: true
93-
}
88+
export type GetStaticPropsResult<P> =
89+
| { props: P; revalidate?: number | boolean }
90+
| { unstable_redirect: Redirect; revalidate?: number | boolean }
91+
| { notFound: true }
9492

9593
export type GetStaticProps<
9694
P extends { [key: string]: any } = { [key: string]: any },
@@ -133,15 +131,9 @@ export type GetServerSidePropsContext<
133131
}
134132

135133
export type GetServerSidePropsResult<P> =
136-
| {
137-
props: P
138-
}
139-
| {
140-
unstable_redirect: Redirect
141-
}
142-
| {
143-
notFound: true
144-
}
134+
| { props: P }
135+
| { unstable_redirect: Redirect }
136+
| { notFound: true }
145137

146138
export type GetServerSideProps<
147139
P extends { [key: string]: any } = { [key: string]: any },

0 commit comments

Comments
 (0)