Skip to content

Commit e5bb89b

Browse files
committed
Chore: add build time to env and update API fetch to prevent caching with timestamp query parameter
1 parent e7d8ffb commit e5bb89b

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

next.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const nextConfig = {
1414
],
1515
},
1616

17+
env: {
18+
NEXT_PUBLIC_BUILD_TIME: `${Date.now()}`,
19+
},
20+
1721
output: "export",
1822
// basePath: "/proxmox-helper-scripts",
1923
};

src/app/scripts/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ function ScriptContent() {
4747
};
4848

4949
useEffect(() => {
50-
fetch("api/categories")
50+
fetch(
51+
`api/categories?_=${process.env.NEXT_PUBLIC_BUILD_TIME || Date.now()}`,
52+
)
5153
.then((response) => response.json())
5254
.then((categories) => {
5355
const sortedCategories = sortCategories(categories);

src/components/CommandMenu.tsx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,13 @@ export default function CommandMenu() {
5050
}, []);
5151

5252
React.useEffect(() => {
53-
const fetchCategories = async (): Promise<void> => {
54-
try {
55-
const response = await fetch("api/categories");
56-
if (!response.ok) {
57-
throw new Error("Failed to fetch categories");
58-
}
59-
const categories: Category[] = await response.json();
60-
if (categories.length === 0) {
61-
throw new Error("Empty response");
62-
}
53+
fetch(`api/categories?_=${process.env.NEXT_PUBLIC_BUILD_TIME || Date.now()}`)
54+
.then((response) => response.json())
55+
.then((categories) => {
6356
const sortedCategories = sortCategories(categories);
6457
setLinks(sortedCategories);
65-
} catch (error) {
66-
console.error(error);
67-
}
68-
};
69-
70-
fetchCategories();
58+
})
59+
.catch((error) => console.error(error));
7160
}, []);
7261

7362
return (

0 commit comments

Comments
 (0)