Skip to content

Commit

Permalink
Update type
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 27, 2020
1 parent 6e49927 commit 9fa2c42
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
14 changes: 9 additions & 5 deletions packages/next/next-server/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ export async function renderToHTML(
throw new Error(invalidKeysMsg('getServerSideProps', invalidKeys))
}

if (data.unstable_notFound) {
if ('unstable_notFound' in data) {
if (pathname === '/404') {
throw new Error(
`The /404 page can not return unstable_notFound in "getStaticProps", please remove it to continue!`
Expand All @@ -775,13 +775,13 @@ export async function renderToHTML(
}

if (
data.unstable_redirect &&
'unstable_redirect' in data &&
typeof data.unstable_redirect === 'object'
) {
checkRedirectValues(data.unstable_redirect, req)

if (isDataReq) {
data.props = {
;(data as any).props = {
__N_REDIRECT: data.unstable_redirect.destination,
}
} else {
Expand All @@ -792,15 +792,19 @@ export async function renderToHTML(

if (
(dev || isBuildTimeSSG) &&
!isSerializableProps(pathname, 'getServerSideProps', data.props)
!isSerializableProps(
pathname,
'getServerSideProps',
(data as any).props
)
) {
// this fn should throw an error instead of ever returning `false`
throw new Error(
'invariant: getServerSideProps did not return valid props. Please report this.'
)
}

props.pageProps = Object.assign({}, props.pageProps, data.props)
props.pageProps = Object.assign({}, props.pageProps, (data as any).props)
;(renderOpts as any).pageData = props
}
} catch (dataFetchError) {
Expand Down
15 changes: 10 additions & 5 deletions packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,16 @@ export type GetServerSidePropsContext<
locales?: string[]
}

export type GetServerSidePropsResult<P> = {
props?: P
unstable_redirect?: Redirect
unstable_notFound?: true
}
export type GetServerSidePropsResult<P> =
| {
props: P
}
| {
unstable_redirect: Redirect
}
| {
unstable_notFound: true
}

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

0 comments on commit 9fa2c42

Please sign in to comment.