From 4d206ac3ddb27d9df4db774e0f99920326ef2c81 Mon Sep 17 00:00:00 2001
From: Kevin Stubbs
Date: Thu, 5 Sep 2024 13:22:21 +0200
Subject: [PATCH 1/3] Add node engine to package.jsons and gracefully handle
when the PCC connection isn't correctly set up
---
.../next.config.js | 8 +-
.../nextjs-starter-approuter-ts/package.json | 3 +
starters/nextjs-starter-ts/next.config.js | 8 +-
starters/nextjs-starter-ts/package.json | 3 +
.../pages/examples/ssg-isr/[uri].tsx | 102 ++++++++++--------
.../pages/examples/ssg-isr/index.tsx | 22 ++--
starters/nextjs-starter/next.config.js | 8 +-
starters/nextjs-starter/package.json | 3 +
8 files changed, 95 insertions(+), 62 deletions(-)
diff --git a/starters/nextjs-starter-approuter-ts/next.config.js b/starters/nextjs-starter-approuter-ts/next.config.js
index f1d75f86..566ab0e5 100644
--- a/starters/nextjs-starter-approuter-ts/next.config.js
+++ b/starters/nextjs-starter-approuter-ts/next.config.js
@@ -9,12 +9,12 @@ require("dotenv").config({
function ensureEnvVariable(name) {
if (process.env[name] == null) {
if (process.env.NODE_ENV === "development") {
- throw new Error(
- `No ${name} found.\nSee the README.md for information on setting this variable locally.`,
+ console.error(
+ `No ${name} found.\nSee the README.md for information on setting this variable locally.`
);
} else if (process.env.NODE_ENV === "production") {
- throw new Error(
- `No ${name} Endpoint found.\nLink to your PCC Instance or set the ${name} environment variable in the settings tab in the dashboard\nIf your site does not require a backend to build, remove this check from the next.config.js.`,
+ console.warn(
+ `No ${name} environment variable found.\nLink to your PCC Instance or set the ${name} environment variable in the settings tab in the dashboard\nIf your site does not require a backend to build, remove this check from the next.config.js.`
);
}
}
diff --git a/starters/nextjs-starter-approuter-ts/package.json b/starters/nextjs-starter-approuter-ts/package.json
index 884dbf10..d184f59d 100644
--- a/starters/nextjs-starter-approuter-ts/package.json
+++ b/starters/nextjs-starter-approuter-ts/package.json
@@ -22,6 +22,9 @@
"update-snapshots": "vitest run --update --silent",
"coverage": "vitest run --coverage"
},
+ "engines": {
+ "node": ">=18.0.0"
+ },
"dependencies": {
"@pantheon-systems/pcc-react-sdk": "~3.7.0",
"@tailwindcss/typography": "^0.5.10",
diff --git a/starters/nextjs-starter-ts/next.config.js b/starters/nextjs-starter-ts/next.config.js
index f1d75f86..566ab0e5 100644
--- a/starters/nextjs-starter-ts/next.config.js
+++ b/starters/nextjs-starter-ts/next.config.js
@@ -9,12 +9,12 @@ require("dotenv").config({
function ensureEnvVariable(name) {
if (process.env[name] == null) {
if (process.env.NODE_ENV === "development") {
- throw new Error(
- `No ${name} found.\nSee the README.md for information on setting this variable locally.`,
+ console.error(
+ `No ${name} found.\nSee the README.md for information on setting this variable locally.`
);
} else if (process.env.NODE_ENV === "production") {
- throw new Error(
- `No ${name} Endpoint found.\nLink to your PCC Instance or set the ${name} environment variable in the settings tab in the dashboard\nIf your site does not require a backend to build, remove this check from the next.config.js.`,
+ console.warn(
+ `No ${name} environment variable found.\nLink to your PCC Instance or set the ${name} environment variable in the settings tab in the dashboard\nIf your site does not require a backend to build, remove this check from the next.config.js.`
);
}
}
diff --git a/starters/nextjs-starter-ts/package.json b/starters/nextjs-starter-ts/package.json
index 27aeda44..b5608d9a 100644
--- a/starters/nextjs-starter-ts/package.json
+++ b/starters/nextjs-starter-ts/package.json
@@ -22,6 +22,9 @@
"update-snapshots": "vitest run --update --silent",
"coverage": "vitest run --coverage"
},
+ "engines": {
+ "node": ">=18.0.0"
+ },
"dependencies": {
"@pantheon-systems/pcc-react-sdk": "~3.7.0",
"@pantheon-systems/pds-toolkit-react": "1.0.0-dev.55",
diff --git a/starters/nextjs-starter-ts/pages/examples/ssg-isr/[uri].tsx b/starters/nextjs-starter-ts/pages/examples/ssg-isr/[uri].tsx
index a7559868..7e3d47f7 100644
--- a/starters/nextjs-starter-ts/pages/examples/ssg-isr/[uri].tsx
+++ b/starters/nextjs-starter-ts/pages/examples/ssg-isr/[uri].tsx
@@ -62,61 +62,77 @@ export const getStaticProps: GetStaticProps<{}, { uri: string }> = async ({
};
}
- const article = await PCCConvenienceFunctions.getArticleBySlugOrId(uri);
+ try {
+ const article = await PCCConvenienceFunctions.getArticleBySlugOrId(uri);
+
+ if (!article) {
+ return {
+ notFound: true,
+ };
+ }
+
+ const recommendedArticles =
+ await PCCConvenienceFunctions.getRecommendedArticles(article.id);
- if (!article) {
+ return {
+ props: {
+ article,
+ recommendedArticles,
+ },
+ };
+ } catch (e) {
+ console.error(e);
return {
notFound: true,
};
}
-
- const recommendedArticles =
- await PCCConvenienceFunctions.getRecommendedArticles(article.id);
-
- return {
- props: {
- article,
- recommendedArticles,
- },
- };
};
export const getStaticPaths: GetStaticPaths = async () => {
- const publishedArticles = await PCCConvenienceFunctions.getAllArticles(
- {
- publishingLevel: "PRODUCTION",
- },
- {
- publishStatus: "published",
- },
- );
-
- const pagePaths = publishedArticles.map((article) => {
- const id = article.id;
- const slug = article.metadata.slug;
-
- // Generate both slug and id paths for each article
- const paths = [
+ try {
+ const publishedArticles = await PCCConvenienceFunctions.getAllArticles(
{
- params: {
- uri: id,
- },
+ publishingLevel: "PRODUCTION",
},
- ];
+ {
+ publishStatus: "published",
+ },
+ );
+
+ const pagePaths = publishedArticles.map((article) => {
+ const id = article.id;
+ const slug = article.metadata.slug;
- if (slug) {
- paths.push({
- params: {
- uri: String(slug),
+ // Generate both slug and id paths for each article
+ const paths = [
+ {
+ params: {
+ uri: id,
+ },
},
- });
- }
+ ];
+
+ if (slug) {
+ paths.push({
+ params: {
+ uri: String(slug),
+ },
+ });
+ }
- return paths;
- });
+ return paths;
+ });
- return {
- paths: pagePaths.flat(),
- fallback: "blocking",
- };
+ return {
+ paths: pagePaths.flat(),
+ fallback: "blocking",
+ };
+ } catch (e) {
+ console.error(e);
+
+ return {
+ paths: [],
+ fallback: "blocking",
+ };
+ }
};
diff --git a/starters/nextjs-starter-ts/pages/examples/ssg-isr/index.tsx b/starters/nextjs-starter-ts/pages/examples/ssg-isr/index.tsx
index 349cff11..bf51fc30 100644
--- a/starters/nextjs-starter-ts/pages/examples/ssg-isr/index.tsx
+++ b/starters/nextjs-starter-ts/pages/examples/ssg-isr/index.tsx
@@ -34,12 +34,20 @@ export default function SSGISRExampleTemplate({ articles }) {
}
export async function getStaticProps() {
- const articles = await PCCConvenienceFunctions.getAllArticles();
+ try {
+ const articles = await PCCConvenienceFunctions.getAllArticles();
- return {
- props: {
- articles,
- },
- revalidate: 60,
- };
+ return {
+ props: {
+ articles,
+ },
+ revalidate: 60,
+ };
+ } catch (e) {
+ console.error(e);
+
+ return {
+ notFound: true,
+ };
+ }
}
diff --git a/starters/nextjs-starter/next.config.js b/starters/nextjs-starter/next.config.js
index f1d75f86..566ab0e5 100644
--- a/starters/nextjs-starter/next.config.js
+++ b/starters/nextjs-starter/next.config.js
@@ -9,12 +9,12 @@ require("dotenv").config({
function ensureEnvVariable(name) {
if (process.env[name] == null) {
if (process.env.NODE_ENV === "development") {
- throw new Error(
- `No ${name} found.\nSee the README.md for information on setting this variable locally.`,
+ console.error(
+ `No ${name} found.\nSee the README.md for information on setting this variable locally.`
);
} else if (process.env.NODE_ENV === "production") {
- throw new Error(
- `No ${name} Endpoint found.\nLink to your PCC Instance or set the ${name} environment variable in the settings tab in the dashboard\nIf your site does not require a backend to build, remove this check from the next.config.js.`,
+ console.warn(
+ `No ${name} environment variable found.\nLink to your PCC Instance or set the ${name} environment variable in the settings tab in the dashboard\nIf your site does not require a backend to build, remove this check from the next.config.js.`
);
}
}
diff --git a/starters/nextjs-starter/package.json b/starters/nextjs-starter/package.json
index 904a2149..8d2c6d65 100644
--- a/starters/nextjs-starter/package.json
+++ b/starters/nextjs-starter/package.json
@@ -22,6 +22,9 @@
"update-snapshots": "vitest run --update --silent",
"coverage": "vitest run --coverage"
},
+ "engines": {
+ "node": ">=18.0.0"
+ },
"dependencies": {
"@pantheon-systems/pcc-react-sdk": "~3.7.0",
"@pantheon-systems/pds-toolkit-react": "1.0.0-dev.55",
From f2ee6fa737a85b9766d8908f2d55dc2306ac3674 Mon Sep 17 00:00:00 2001
From: Kevin Stubbs
Date: Thu, 5 Sep 2024 13:37:41 +0200
Subject: [PATCH 2/3] Fix typo in app router starter kit
---
starters/nextjs-starter-approuter-ts/app/examples/page.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/starters/nextjs-starter-approuter-ts/app/examples/page.tsx b/starters/nextjs-starter-approuter-ts/app/examples/page.tsx
index 5297e740..4fc3d6da 100644
--- a/starters/nextjs-starter-approuter-ts/app/examples/page.tsx
+++ b/starters/nextjs-starter-approuter-ts/app/examples/page.tsx
@@ -13,7 +13,7 @@ export default function ExamplesPageTemplate() {
This page outlines a growing list of common use cases that can be
used as a reference when building using this starter kit. If you
don't need them for your site, feel free to delete the
- `pages/examples` directory in your codebase.
+ `app/examples` directory in your codebase.
From a170c5091bbed623ba80c885e615a67992567006 Mon Sep 17 00:00:00 2001
From: Kevin Stubbs
Date: Thu, 5 Sep 2024 13:43:32 +0200
Subject: [PATCH 3/3] Add missing @types/node from typescript starter kits.
Update typescript config links in the next-env.d.ts files.
---
pnpm-lock.yaml | 71 ++-----------------
.../nextjs-starter-approuter-ts/package.json | 1 +
starters/nextjs-starter-ts/next-env.d.ts | 2 +-
starters/nextjs-starter-ts/package.json | 1 +
starters/nextjs-starter/next-env.d.ts | 3 +-
5 files changed, 12 insertions(+), 66 deletions(-)
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6179536f..fd3d0dff 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -793,6 +793,9 @@ importers:
'@tailwindcss/typography':
specifier: 0.5.10
version: 0.5.10(tailwindcss@3.4.1)
+ '@types/node':
+ specifier: ^20.11.21
+ version: 20.16.1
class-variance-authority:
specifier: ^0.7.0
version: 0.7.0
@@ -893,6 +896,9 @@ importers:
'@tailwindcss/typography':
specifier: 0.5.10
version: 0.5.10(tailwindcss@3.4.1)
+ '@types/node':
+ specifier: ^20.11.21
+ version: 20.16.1
class-variance-authority:
specifier: ^0.7.0
version: 0.7.0
@@ -20602,7 +20608,7 @@ snapshots:
'@jest/globals': 29.7.0
'@types/jest': 29.5.1
jest: 29.5.0(@types/node@20.11.21)
- vitest: 1.3.1(@types/node@20.11.21)(sass@1.71.1)
+ vitest: 1.3.1(@types/node@20.11.21)(jsdom@22.1.0)(sass@1.71.1)(terser@5.28.1)
'@testing-library/react@13.4.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
dependencies:
@@ -32494,24 +32500,6 @@ snapshots:
dependencies:
vite: 5.2.13(@types/node@20.16.1)(sass@1.71.1)(terser@5.28.1)
- vite-node@1.3.1(@types/node@20.11.21)(sass@1.71.1):
- dependencies:
- cac: 6.7.14
- debug: 4.3.4
- pathe: 1.1.2
- picocolors: 1.0.0
- vite: 5.1.4(@types/node@20.11.21)(sass@1.71.1)
- transitivePeerDependencies:
- - '@types/node'
- - less
- - lightningcss
- - sass
- - stylus
- - sugarss
- - supports-color
- - terser
- optional: true
-
vite-node@1.3.1(@types/node@20.11.21)(sass@1.71.1)(terser@5.28.1):
dependencies:
cac: 6.7.14
@@ -32619,17 +32607,6 @@ snapshots:
transitivePeerDependencies:
- supports-color
- vite@5.1.4(@types/node@20.11.21)(sass@1.71.1):
- dependencies:
- esbuild: 0.19.12
- postcss: 8.4.38
- rollup: 4.12.0
- optionalDependencies:
- '@types/node': 20.11.21
- fsevents: 2.3.3
- sass: 1.71.1
- optional: true
-
vite@5.1.4(@types/node@20.11.21)(sass@1.71.1)(terser@5.28.1):
dependencies:
esbuild: 0.19.12
@@ -32704,40 +32681,6 @@ snapshots:
- supports-color
- terser
- vitest@1.3.1(@types/node@20.11.21)(sass@1.71.1):
- dependencies:
- '@vitest/expect': 1.3.1
- '@vitest/runner': 1.3.1
- '@vitest/snapshot': 1.3.1
- '@vitest/spy': 1.3.1
- '@vitest/utils': 1.3.1
- acorn-walk: 8.3.2
- chai: 4.4.1
- debug: 4.3.4
- execa: 8.0.1
- local-pkg: 0.5.0
- magic-string: 0.30.10
- pathe: 1.1.2
- picocolors: 1.0.0
- std-env: 3.7.0
- strip-literal: 2.0.0
- tinybench: 2.6.0
- tinypool: 0.8.2
- vite: 5.1.4(@types/node@20.11.21)(sass@1.71.1)
- vite-node: 1.3.1(@types/node@20.11.21)(sass@1.71.1)
- why-is-node-running: 2.2.2
- optionalDependencies:
- '@types/node': 20.11.21
- transitivePeerDependencies:
- - less
- - lightningcss
- - sass
- - stylus
- - sugarss
- - supports-color
- - terser
- optional: true
-
vitest@1.3.1(@types/node@20.16.1)(jsdom@22.1.0)(sass@1.71.1)(terser@5.28.1):
dependencies:
'@vitest/expect': 1.3.1
diff --git a/starters/nextjs-starter-approuter-ts/package.json b/starters/nextjs-starter-approuter-ts/package.json
index d112dc38..1b2d9d52 100644
--- a/starters/nextjs-starter-approuter-ts/package.json
+++ b/starters/nextjs-starter-approuter-ts/package.json
@@ -30,6 +30,7 @@
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@tailwindcss/typography": "0.5.10",
+ "@types/node": "^20.11.21",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"dotenv": "^16.4.5",
diff --git a/starters/nextjs-starter-ts/next-env.d.ts b/starters/nextjs-starter-ts/next-env.d.ts
index 4f11a03d..40c3d680 100644
--- a/starters/nextjs-starter-ts/next-env.d.ts
+++ b/starters/nextjs-starter-ts/next-env.d.ts
@@ -2,4 +2,4 @@
///
// NOTE: This file should not be edited
-// see https://nextjs.org/docs/basic-features/typescript for more information.
+// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
diff --git a/starters/nextjs-starter-ts/package.json b/starters/nextjs-starter-ts/package.json
index 1d1ea796..a96e1974 100644
--- a/starters/nextjs-starter-ts/package.json
+++ b/starters/nextjs-starter-ts/package.json
@@ -30,6 +30,7 @@
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@tailwindcss/typography": "0.5.10",
+ "@types/node": "^20.11.21",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"dotenv": "^16.4.5",
diff --git a/starters/nextjs-starter/next-env.d.ts b/starters/nextjs-starter/next-env.d.ts
index 4f11a03d..b06a1b32 100644
--- a/starters/nextjs-starter/next-env.d.ts
+++ b/starters/nextjs-starter/next-env.d.ts
@@ -2,4 +2,5 @@
///
// NOTE: This file should not be edited
-// see https://nextjs.org/docs/basic-features/typescript for more information.
+// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
+