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<
query: ParsedUrlQuery
preview?: boolean
previewData?: Preview
draftMode?: boolean
resolvedUrl: string
locale?: string
locales?: string[]
......
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 {
props: {
random: Math.random(),
......@@ -10,7 +16,7 @@ export function getStaticProps({ draftMode }) {
}
}
export default function Another(props) {
export default function Another(props: Props) {
return (
<>
<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.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.end('Check your cookies...')
}
export default (req, res) => {
import type { NextApiRequest, NextApiResponse } from 'next'
export default (req: NextApiRequest, res: NextApiResponse) => {
const { draftMode } = req
res.json({ draftMode })
}
import { useState } from 'react'
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 {
props: {
random: Math.random(),
......@@ -11,7 +17,7 @@ export function getStaticProps({ draftMode }) {
}
}
export default function Home(props) {
export default function Home(props: Props) {
const [count, setCount] = useState(0)
return (
<>
......
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
res.setHeader('Cache-Control', 'public, max-age=3600')
return {
......@@ -11,7 +20,7 @@ export function getServerSideProps({ res, draftMode }) {
}
}
export default function SSP(props) {
export default function SSP(props: Props) {
return (
<>
<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