-
Notifications
You must be signed in to change notification settings - Fork 73
Add an isr route to the playground #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
// This test relies on using `.dev.vars` to set the environment to `development` | ||
// However `next build` is not passed an environment, so we do not want to cache | ||
// the output. | ||
export const dynamic = "force-dynamic"; | ||
|
||
export async function GET() { | ||
return new Response(JSON.stringify(process.env)); | ||
} |
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,30 @@ | ||
// Imported from https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration | ||
interface Post { | ||
id: string; | ||
title: string; | ||
content: string; | ||
} | ||
|
||
// Next.js will invalidate the cache when a | ||
// request comes in, at most once every 1 hour. | ||
export const revalidate = 3600; | ||
|
||
// We'll prerender only the params from `generateStaticParams` at build time. | ||
// If a request comes in for a path that hasn't been generated, | ||
// Next.js will server-render the page on-demand. | ||
export const dynamicParams = true; | ||
|
||
export async function generateStaticParams() { | ||
return [{ id: "1" }, { id: "2" }, { id: "3" }]; | ||
} | ||
|
||
export default async function Page({ params }: { params: Promise<{ id: string }> }) { | ||
const id = (await params).id; | ||
const post: Post = await fetch(`https://api.vercel.app/blog/${id}`).then((res) => res.json()); | ||
return ( | ||
<main> | ||
<h1>{post.title}</h1> | ||
<p>{post.content}</p> | ||
</main> | ||
); | ||
} |
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,29 @@ | ||
// Imported from https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration | ||
interface Post { | ||
id: string; | ||
title: string; | ||
content: string; | ||
} | ||
|
||
// Next.js will invalidate the cache when a | ||
// request comes in, at most once every 1 hour. | ||
export const revalidate = 3600; | ||
|
||
// We'll prerender only the params from `generateStaticParams` at build time. | ||
// If a request comes in for a path that hasn't been generated, it will 404. | ||
export const dynamicParams = false; | ||
|
||
export async function generateStaticParams() { | ||
return [{ id: "1" }, { id: "2" }, { id: "3" }]; | ||
} | ||
|
||
export default async function Page({ params }: { params: Promise<{ id: string }> }) { | ||
const id = (await params).id; | ||
const post: Post = await fetch(`https://api.vercel.app/blog/${id}`).then((res) => res.json()); | ||
return ( | ||
<main> | ||
<h1>{post.title}</h1> | ||
<p>{post.content}</p> | ||
</main> | ||
); | ||
} |
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,30 @@ | ||
import { test, expect, type APIResponse } from "@playwright/test"; | ||
import type { BinaryLike } from "node:crypto"; | ||
import { createHash } from "node:crypto"; | ||
|
||
test("Generated pages exist", async ({ page }) => { | ||
const generatedIds = [1, 2, 3]; | ||
let res: APIResponse; | ||
for (const id of generatedIds) { | ||
res = await page.request.get(`/isr/${id}/dynamic`); | ||
expect(res.status()).toBe(200); | ||
res = await page.request.get(`/isr/${id}/no-dynamic`); | ||
expect(res.status()).toBe(200); | ||
} | ||
}); | ||
|
||
test("Non generated pages 404 when dynamic is false", async ({ page }) => { | ||
const generatedIds = [4, 5, 6]; | ||
for (const id of generatedIds) { | ||
const res = await page.request.get(`/isr/${id}/no-dynamic`); | ||
expect(res.status()).toBe(404); | ||
} | ||
}); | ||
|
||
test("Non generated pages are generated when dynamic is true", async ({ page }) => { | ||
const generatedIds = [4, 5, 6]; | ||
for (const id of generatedIds) { | ||
const res = await page.request.get(`/isr/${id}/dynamic`); | ||
expect(res.status()).toBe(200); | ||
} | ||
}); |
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
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.