mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-09-08 21:05:34 -04:00
wrap hit counter with an error boundary in case the API falls on its face again
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
20.10.0
|
20.11.0
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import useSWRImmutable from "swr/immutable";
|
import useSWRImmutable from "swr/immutable";
|
||||||
|
import { useErrorBoundary } from "react-error-boundary";
|
||||||
import commaNumber from "comma-number";
|
import commaNumber from "comma-number";
|
||||||
import Loading from "../Loading";
|
import Loading from "../Loading";
|
||||||
import fetcher from "../../lib/helpers/fetcher";
|
import fetcher from "../../lib/helpers/fetcher";
|
||||||
@@ -9,6 +10,8 @@ export type HitCounterProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const HitCounter = ({ slug }: HitCounterProps) => {
|
const HitCounter = ({ slug }: HitCounterProps) => {
|
||||||
|
const { showBoundary } = useErrorBoundary();
|
||||||
|
|
||||||
// use immutable SWR to avoid double (or more) counting views:
|
// use immutable SWR to avoid double (or more) counting views:
|
||||||
// https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations
|
// https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations
|
||||||
const { data, error } = useSWRImmutable<PageStats>(
|
const { data, error } = useSWRImmutable<PageStats>(
|
||||||
@@ -18,8 +21,9 @@ const HitCounter = ({ slug }: HitCounterProps) => {
|
|||||||
fetcher
|
fetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
// fail secretly
|
// fail somewhat silently, see error boundary in NoteMeta component
|
||||||
if (error) {
|
if (error) {
|
||||||
|
showBoundary(`${error}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ErrorBoundary } from "react-error-boundary";
|
||||||
import Link from "../Link";
|
import Link from "../Link";
|
||||||
import Time from "../Time";
|
import Time from "../Time";
|
||||||
import HitCounter from "../HitCounter";
|
import HitCounter from "../HitCounter";
|
||||||
@@ -106,8 +107,11 @@ const NoteMeta = ({ slug, date, title, htmlTitle, tags }: NoteMetaProps) => {
|
|||||||
marginRight: 0,
|
marginRight: 0,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{/* completely hide this block if anything goes wrong on the backend */}
|
||||||
|
<ErrorBoundary fallback={null}>
|
||||||
<Icon as={FiEye} />
|
<Icon as={FiEye} />
|
||||||
<HitCounter slug={`notes/${slug}`} />
|
<HitCounter slug={`notes/${slug}`} />
|
||||||
|
</ErrorBoundary>
|
||||||
</MetaItem>
|
</MetaItem>
|
||||||
)}
|
)}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
|
|||||||
+16
-16
@@ -23,9 +23,9 @@
|
|||||||
"@neondatabase/serverless": "^0.6.1",
|
"@neondatabase/serverless": "^0.6.1",
|
||||||
"@novnc/novnc": "1.4.0",
|
"@novnc/novnc": "1.4.0",
|
||||||
"@octokit/graphql": "^7.0.2",
|
"@octokit/graphql": "^7.0.2",
|
||||||
"@octokit/graphql-schema": "^14.47.0",
|
"@octokit/graphql-schema": "^14.47.1",
|
||||||
"@prisma/adapter-neon": "^5.8.0",
|
"@prisma/adapter-neon": "^5.8.1",
|
||||||
"@prisma/client": "^5.8.0",
|
"@prisma/client": "^5.8.1",
|
||||||
"@react-spring/web": "^9.7.3",
|
"@react-spring/web": "^9.7.3",
|
||||||
"@stitches/react": "1.3.1-1",
|
"@stitches/react": "1.3.1-1",
|
||||||
"@vercel/edge": "^1.1.1",
|
"@vercel/edge": "^1.1.1",
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
"formik": "^2.4.5",
|
"formik": "^2.4.5",
|
||||||
"geist": "^1.2.1",
|
"geist": "^1.2.1",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"next": "14.0.4",
|
"next": "14.1.0",
|
||||||
"next-mdx-remote": "^4.4.1",
|
"next-mdx-remote": "^4.4.1",
|
||||||
"next-seo": "^6.4.0",
|
"next-seo": "^6.4.0",
|
||||||
"obj-str": "^1.1.0",
|
"obj-str": "^1.1.0",
|
||||||
@@ -76,31 +76,31 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@jakejarvis/eslint-config": "^3.1.0",
|
"@jakejarvis/eslint-config": "^3.1.0",
|
||||||
"@types/comma-number": "^2.1.2",
|
"@types/comma-number": "^2.1.2",
|
||||||
"@types/node": "^20.11.0",
|
"@types/node": "^20.11.5",
|
||||||
"@types/novnc__novnc": "^1.3.4",
|
"@types/novnc__novnc": "^1.3.4",
|
||||||
"@types/prop-types": "^15.7.11",
|
"@types/prop-types": "^15.7.11",
|
||||||
"@types/react": "^18.2.47",
|
"@types/react": "^18.2.48",
|
||||||
"@types/react-dom": "^18.2.18",
|
"@types/react-dom": "^18.2.18",
|
||||||
"@types/react-is": "^18.2.4",
|
"@types/react-is": "^18.2.4",
|
||||||
"@types/uglify-js": "^3.17.4",
|
"@types/uglify-js": "^3.17.4",
|
||||||
"@types/ws": "^8.5.10",
|
"@types/ws": "^8.5.10",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
||||||
"@typescript-eslint/parser": "^6.18.1",
|
"@typescript-eslint/parser": "^6.19.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"eslint": "~8.56.0",
|
"eslint": "~8.56.0",
|
||||||
"eslint-config-next": "14.0.4",
|
"eslint-config-next": "14.1.0",
|
||||||
"eslint-config-prettier": "~9.1.0",
|
"eslint-config-prettier": "~9.1.0",
|
||||||
"eslint-plugin-mdx": "~3.1.4",
|
"eslint-plugin-mdx": "~3.1.5",
|
||||||
"eslint-plugin-prettier": "~5.1.3",
|
"eslint-plugin-prettier": "~5.1.3",
|
||||||
"lint-staged": "^15.2.0",
|
"lint-staged": "^15.2.0",
|
||||||
"prettier": "^3.1.1",
|
"prettier": "^3.2.4",
|
||||||
"prisma": "^5.8.0",
|
"prisma": "^5.8.1",
|
||||||
"simple-git-hooks": "^2.9.0",
|
"simple-git-hooks": "^2.9.0",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"uglify-js": "^3.17.4"
|
"uglify-js": "^3.17.4"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"sharp": "^0.33.1"
|
"sharp": "^0.33.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.x"
|
"node": ">=20.x"
|
||||||
@@ -117,9 +117,9 @@
|
|||||||
"eslint"
|
"eslint"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@8.14.0",
|
"packageManager": "pnpm@8.14.1",
|
||||||
"volta": {
|
"volta": {
|
||||||
"node": "20.10.0",
|
"node": "20.11.0",
|
||||||
"pnpm": "8.14.0"
|
"pnpm": "8.14.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+256
-280
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user