Unverified Commit f56722c9 authored by Steven's avatar Steven Committed by GitHub

fix: add missing `draftMode` type to GetServerSidePropsContext (#50184)

This `draftMode` prop was missing from the previous PR:

- https://github.com/vercel/next.js/pull/48669 

It was added on `GetStaticPropsContext` but not on
`GetServerSidePropsContext` so this PR fixes it.

---------
parent a1633948
...@@ -251,6 +251,7 @@ export type GetServerSidePropsContext< ...@@ -251,6 +251,7 @@ export type GetServerSidePropsContext<
query: ParsedUrlQuery query: ParsedUrlQuery
preview?: boolean preview?: boolean
previewData?: Preview previewData?: Preview
draftMode?: boolean
resolvedUrl: string resolvedUrl: string
locale?: string locale?: string
locales?: string[] locales?: string[]
......
import Link from 'next/link' import Link from 'next/link'
import type { GetStaticProps } from 'next'
export function getStaticProps({ draftMode }) { type Props = {
random: number
draftMode: string
}
export const getStaticProps: GetStaticProps<Props> = ({ draftMode }) => {
return { return {
props: { props: {
random: Math.random(), random: Math.random(),
...@@ -10,7 +16,7 @@ export function getStaticProps({ draftMode }) { ...@@ -10,7 +16,7 @@ export function getStaticProps({ draftMode }) {
} }
} }
export default function Another(props) { export default function Another(props: Props) {
return ( return (
<> <>
<h1>Another</h1> <h1>Another</h1>
......
export default function handler(_req, res) { import type { NextApiRequest, NextApiResponse } from 'next'
export default function handler(_req: NextApiRequest, res: NextApiResponse) {
res.setDraftMode({ enable: false }) res.setDraftMode({ enable: false })
res.end('Check your cookies...') res.end('Check your cookies...')
} }
export default function handler(_req, res) { import type { NextApiRequest, NextApiResponse } from 'next'
export default function handler(_req: NextApiRequest, res: NextApiResponse) {
res.setDraftMode({ enable: true }) res.setDraftMode({ enable: true })
res.end('Check your cookies...') res.end('Check your cookies...')
} }
export default (req, res) => { import type { NextApiRequest, NextApiResponse } from 'next'
export default (req: NextApiRequest, res: NextApiResponse) => {
const { draftMode } = req const { draftMode } = req
res.json({ draftMode }) res.json({ draftMode })
} }
import { useState } from 'react' import { useState } from 'react'
import Link from 'next/link' import Link from 'next/link'
import type { GetStaticProps } from 'next'
export function getStaticProps({ draftMode }) { type Props = {
random: number
draftMode: string
}
export const getStaticProps: GetStaticProps<Props> = ({ draftMode }) => {
return { return {
props: { props: {
random: Math.random(), random: Math.random(),
...@@ -11,7 +17,7 @@ export function getStaticProps({ draftMode }) { ...@@ -11,7 +17,7 @@ export function getStaticProps({ draftMode }) {
} }
} }
export default function Home(props) { export default function Home(props: Props) {
const [count, setCount] = useState(0) const [count, setCount] = useState(0)
return ( return (
<> <>
......
import Link from 'next/link' import Link from 'next/link'
import type { GetServerSideProps } from 'next'
export function getServerSideProps({ res, draftMode }) { type Props = {
random: number
draftMode: string
}
export const getServerSideProps: GetServerSideProps<Props> = async ({
res,
draftMode,
}) => {
// test override header // test override header
res.setHeader('Cache-Control', 'public, max-age=3600') res.setHeader('Cache-Control', 'public, max-age=3600')
return { return {
...@@ -11,7 +20,7 @@ export function getServerSideProps({ res, draftMode }) { ...@@ -11,7 +20,7 @@ export function getServerSideProps({ res, draftMode }) {
} }
} }
export default function SSP(props) { export default function SSP(props: Props) {
return ( return (
<> <>
<h1>Server Side Props</h1> <h1>Server Side Props</h1>
......
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment