This repository was archived by the owner on May 10, 2021. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 68
Support for SSG preview mode #50
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
403fbbd
add support for preview mode of pre-rendered pages using getStaticProps
lindsaylevine 588d82b
remove README caveat
lindsaylevine ba805da
Add Cypress tests: Optional catch-all route at root-level
FinnWoelm 933520e
Cleanup: Remove unnecessary require
FinnWoelm f4e189f
miscellaneous finishing touches for ssg preview mode
lindsaylevine 40bcbf9
move preview mode note in readme and update isroutewithfallback helper
lindsaylevine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
| @@ -39,3 +39,6 @@ jspm_packages | |
| ||
# OS | ||
.DS_Store | ||
| ||
# Local Netlify folder | ||
.netlify |
This file contains hidden or 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
9 changes: 9 additions & 0 deletions 9 cypress/fixtures/pages-with-optionalCatchAll-at-root/[[...slug]].js
This file contains hidden or 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,9 @@ | ||
const Page = () => <p>root-level optional-catch-all</p>; | ||
| ||
export async function getServerSideProps() { | ||
return { | ||
props: {}, | ||
}; | ||
} | ||
| ||
export default Page; |
9 changes: 9 additions & 0 deletions 9 cypress/fixtures/pages-with-optionalCatchAll-at-root/static.js
This file contains hidden or 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,9 @@ | ||
const Static = () => <p>static page</p>; | ||
| ||
export async function getStaticProps() { | ||
return { | ||
props: {}, | ||
}; | ||
} | ||
| ||
export default Static; |
27 changes: 27 additions & 0 deletions 27 cypress/fixtures/pages-with-optionalCatchAll-at-root/subfolder/[id].js
This file contains hidden or 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 @@ | ||
const Static = () => <p>static page in subfolder</p>; | ||
| ||
export async function getStaticPaths() { | ||
return { | ||
paths: [ | ||
{ | ||
params: { | ||
id: "static", | ||
}, | ||
}, | ||
{ | ||
params: { | ||
id: "test", | ||
}, | ||
}, | ||
], | ||
fallback: true, | ||
}; | ||
} | ||
| ||
export async function getStaticProps() { | ||
return { | ||
props: {}, | ||
}; | ||
} | ||
| ||
export default Static; |
This file contains hidden or 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,12 @@ | ||
export default async function preview(req, res) { | ||
const { query } = req; | ||
const { id } = query; | ||
| ||
// Enable Preview Mode by setting the cookies | ||
res.setPreviewData({}); | ||
| ||
// Redirect to the path from the fetched post | ||
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities | ||
res.writeHead(307, { Location: `/previewTest/static` }); | ||
res.end(); | ||
} |
This file contains hidden or 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 hidden or 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,45 @@ | ||
import Link from "next/link"; | ||
| ||
const StaticTest = ({ number }) => { | ||
return ( | ||
<div> | ||
<p> | ||
This page uses getStaticProps() and is SSRed when in preview mode. | ||
<br /> | ||
<br /> | ||
By default, it shows the TV show by ID (as static HTML). | ||
<br /> | ||
But when in preview mode, it shows person by ID instead (SSRed). | ||
</p> | ||
| ||
<hr /> | ||
| ||
<h1>Number: {number}</h1> | ||
| ||
<Link href="/"> | ||
<a>Go back home</a> | ||
</Link> | ||
</div> | ||
); | ||
}; | ||
| ||
export const getStaticProps = async ({ preview }) => { | ||
let number; | ||
| ||
// In preview mode, use odd number | ||
if (preview) { | ||
number = 3; | ||
} | ||
// In normal mode, use even number | ||
else { | ||
number = 4; | ||
} | ||
lindsaylevine marked this conversation as resolved. Show resolved Hide resolved | ||
| ||
return { | ||
props: { | ||
number, | ||
}, | ||
}; | ||
}; | ||
| ||
export default StaticTest; |
This file contains hidden or 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 @@ | ||
a text file |
This file contains hidden or 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 @@ | ||
a text file in a folder |
This file contains hidden or 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 @@ | ||
a text file in a subfolder |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.