Skip to content

Commit

Permalink
Revalidate whole path for 404 and 307 paths, new pages and changed re…
Browse files Browse the repository at this point in the history
…directs
  • Loading branch information
pookmish committed Dec 16, 2024
1 parent 0b738a3 commit 9c2159b
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 229 deletions.
15 changes: 14 additions & 1 deletion app/api/revalidate/route.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NextRequest, NextResponse} from "next/server"
import {revalidateTag, unstable_cache as nextCache} from "next/cache"
import {revalidatePath, revalidateTag, unstable_cache as nextCache} from "next/cache"
import {getEntityFromPath} from "@/lib/gql/fetcher"

export const revalidate = 0
Expand All @@ -21,6 +21,19 @@ export const GET = async (request: NextRequest) => {
const path = request.nextUrl.searchParams.get("slug")
if (!path || path.startsWith("/node/")) return NextResponse.json({message: "Invalid slug"}, {status: 400})

if (!path.startsWith("/tags/") && process.env.NEXT_PUBLIC_DOMAIN) {
// 404 and 307 path responses are cached heavily. We need to invalidate the
// path, not just the tags.
await fetch(`${process.env.NEXT_PUBLIC_DOMAIN}${path}`, {redirect: "manual"})
.then(res => {
if (!res.ok) {
revalidatePath(path)
return NextResponse.json({revalidated: true, path})
}
})
.catch(_e => console.warn("something went wrong checking for path"))
}

const tagsInvalidated = path.includes("/tags/") ? [] : [`paths:${path}`]
if (path.startsWith("/tags/"))
path
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@
"dependencies": {
"@formkit/auto-animate": "^0.8.2",
"@heroicons/react": "^2.2.0",
"@mui/base": "5.0.0-beta.64",
"@next/third-parties": "15.0.4",
"@mui/base": "5.0.0-beta.66",
"@next/third-parties": "15.1.0",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.15",
"@tanstack/react-query": "^5.62.3",
"@types/node": "^22.10.1",
"@tanstack/react-query": "^5.62.7",
"@types/node": "^22.10.2",
"@types/react": "^19.0.1",
"autoprefixer": "^10.4.20",
"axios": "^1.7.9",
"critters": "^0.0.25",
"decanter": "^7.3.0",
"graphql": "^16.9.0",
"graphql": "^16.10.0",
"graphql-request": "^7.1.2",
"graphql-tag": "^2.12.6",
"html-entities": "^2.5.2",
"html-react-parser": "^5.2.0",
"html-react-parser": "^5.2.1",
"jsona": "^1.12.1",
"next": "15.0.4",
"next": "15.1.0",
"next-drupal": "^1.6.0",
"postcss": "^8.4.49",
"react": "19.0.0",
"react-aria": "^3.36.0",
"react-dom": "19.0.0",
"react-error-boundary": "^4.1.2",
"react-focus-lock": "^2.13.2",
"react-focus-lock": "^2.13.5",
"react-obfuscate": "^3.7.0",
"react-obfuscate-email": "^1.1.5",
"react-stately": "^3.34.0",
Expand All @@ -57,13 +57,13 @@
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "4.4.0",
"@types/qs": "^6.9.17",
"eslint": "^9.16.0",
"eslint-config-next": "15.0.4",
"eslint": "^9.17.0",
"eslint-config-next": "15.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.4.2",
"prettier-plugin-tailwindcss": "^0.6.9",
"typescript-eslint": "^8.17.0"
"typescript-eslint": "^8.18.1"
},
"packageManager": "[email protected]",
"resolutions": {
Expand Down
Loading

0 comments on commit 9c2159b

Please sign in to comment.