Skip to content

Commit

Permalink
fix: add missing draftMode type to GetServerSidePropsContext (#50184)
Browse files Browse the repository at this point in the history
This `draftMode` prop was missing from the previous PR:

- #48669 

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

---------
  • Loading branch information
styfle committed May 22, 2023
1 parent a163394 commit f56722c
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/next/types/index.d.ts
Expand Up @@ -251,6 +251,7 @@ export type GetServerSidePropsContext<
query: ParsedUrlQuery
preview?: boolean
previewData?: Preview
draftMode?: boolean
resolvedUrl: string
locale?: string
locales?: string[]
Expand Down
@@ -1,6 +1,12 @@
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(),
Expand All @@ -10,7 +16,7 @@ export function getStaticProps({ draftMode }) {
}
}

export default function Another(props) {
export default function Another(props: Props) {
return (
<>
<h1>Another</h1>
Expand Down
4 changes: 0 additions & 4 deletions test/integration/draft-mode/pages/api/disable.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/integration/draft-mode/pages/api/disable.ts
@@ -0,0 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default function handler(_req: NextApiRequest, res: NextApiResponse) {
res.setDraftMode({ enable: false })
res.end('Check your cookies...')
}
4 changes: 0 additions & 4 deletions test/integration/draft-mode/pages/api/enable.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/integration/draft-mode/pages/api/enable.ts
@@ -0,0 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default function handler(_req: NextApiRequest, res: NextApiResponse) {
res.setDraftMode({ enable: true })
res.end('Check your cookies...')
}
4 changes: 0 additions & 4 deletions test/integration/draft-mode/pages/api/read.js

This file was deleted.

6 changes: 6 additions & 0 deletions test/integration/draft-mode/pages/api/read.ts
@@ -0,0 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default (req: NextApiRequest, res: NextApiResponse) => {
const { draftMode } = req
res.json({ draftMode })
}
@@ -1,7 +1,13 @@
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(),
Expand All @@ -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 (
<>
Expand Down
@@ -1,6 +1,15 @@
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 {
Expand All @@ -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>
Expand Down
19 changes: 19 additions & 0 deletions test/integration/draft-mode/tsconfig.json
@@ -0,0 +1,19 @@
{
"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"]
}

0 comments on commit f56722c

Please sign in to comment.