-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft Mode is very similar to Preview Mode but doesn't include any additional data. This PR implements support for Draft Mode in `pages` and a future PR will implement support in `app`. fix NEXT-992
- Loading branch information
Showing
12 changed files
with
430 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Link from 'next/link' | ||
|
||
export function getStaticProps({ draftMode }) { | ||
return { | ||
props: { | ||
random: Math.random(), | ||
draftMode: Boolean(draftMode).toString(), | ||
}, | ||
revalidate: 100000, | ||
} | ||
} | ||
|
||
export default function Another(props) { | ||
return ( | ||
<> | ||
<h1>Another</h1> | ||
<p> | ||
Draft Mode: <em id="draft">{props.draftMode}</em> | ||
</p> | ||
<p> | ||
Random: <em id="rand">{props.random}</em> | ||
</p> | ||
<Link href="/">Go home</Link> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function handler(_req, res) { | ||
res.setDraftMode({ enable: false }) | ||
res.end('Check your cookies...') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function handler(_req, res) { | ||
res.setDraftMode({ enable: true }) | ||
res.end('Check your cookies...') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default (req, res) => { | ||
const { draftMode } = req | ||
res.json({ draftMode }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useState } from 'react' | ||
import Link from 'next/link' | ||
|
||
export function getStaticProps({ draftMode }) { | ||
return { | ||
props: { | ||
random: Math.random(), | ||
draftMode: Boolean(draftMode).toString(), | ||
}, | ||
revalidate: 100000, | ||
} | ||
} | ||
|
||
export default function Home(props) { | ||
const [count, setCount] = useState(0) | ||
return ( | ||
<> | ||
<h1>Home</h1> | ||
<p> | ||
Draft Mode: <em id="draft">{props.draftMode}</em> | ||
</p> | ||
<button id="inc" onClick={() => setCount(count + 1)}> | ||
Increment | ||
</button> | ||
<p> | ||
Count: <span id="count">{count}</span> | ||
</p> | ||
<p> | ||
Random: <em id="rand">{props.random}</em> | ||
</p> | ||
<Link href="/another">Visit another page</Link> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Link from 'next/link' | ||
|
||
export function getServerSideProps({ res, draftMode }) { | ||
// test override header | ||
res.setHeader('Cache-Control', 'public, max-age=3600') | ||
return { | ||
props: { | ||
random: Math.random(), | ||
draftMode: Boolean(draftMode).toString(), | ||
}, | ||
} | ||
} | ||
|
||
export default function SSP(props) { | ||
return ( | ||
<> | ||
<h1>Server Side Props</h1> | ||
<p> | ||
Draft Mode: <em id="draft">{props.draftMode}</em> | ||
</p> | ||
<p> | ||
Random: <em id="rand">{props.random}</em> | ||
</p> | ||
<Link href="/">Go home</Link> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Link from 'next/link' | ||
|
||
export function getStaticProps() { | ||
return { props: {} } | ||
} | ||
|
||
export default function () { | ||
return ( | ||
<main> | ||
<Link href="/" id="to-index"> | ||
To Index | ||
</Link> | ||
</main> | ||
) | ||
} |
Oops, something went wrong.