Skip to content

Commit 349b256

Browse files
committed
fix(sitemap): use delayed timeout so prerender finishes before redirect
1 parent a97cc9a commit 349b256

4 files changed

Lines changed: 45 additions & 17 deletions

File tree

pages/routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export const staticRoutes = [
129129
"/reading",
130130
"/roadmap",
131131
"/settings",
132+
"/sitemap",
132133
"/stories",
133134
"/stories/authors",
134135
"/stories/characters",

public/sitemap/index.html

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/components/AnimatedRoutes.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ const NotebookViewerPage = lazy(
239239
const CommandsPage = lazy(() => import('../pages/CommandsPage'));
240240
const AchievementsPage = lazy(() => import('../pages/AchievementsPage'));
241241
const VocabPage = lazy(() => import('../pages/VocabPage'));
242+
const SitemapPage = lazy(() => import('../pages/SitemapPage'));
242243
const WelcomePage = lazy(() => import('../pages/WelcomePage'));
243244
const DashboardPage = lazy(() => import('../pages/DashboardPage'));
244245
const KnowledgeGraphPage = lazy(() => import('../pages/KnowledgeGraphPage'));
@@ -869,6 +870,22 @@ const AnimatedRoutes = ({
869870
</motion.div>
870871
}
871872
/>
873+
<Route
874+
path="/sitemap"
875+
element={
876+
<motion.div
877+
initial="initial"
878+
animate="in"
879+
exit="out"
880+
variants={pageVariants}
881+
transition={pageTransition}
882+
>
883+
<Suspense fallback={<Loading />}>
884+
<SitemapPage />
885+
</Suspense>
886+
</motion.div>
887+
}
888+
/>
872889
<Route
873890
path="/welcome"
874891
element={

src/pages/SitemapPage.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { useEffect } from 'react';
2+
3+
const SitemapPage = () => {
4+
useEffect(() => {
5+
// Delay the navigation so Puppeteer's prerender snapshot completes first.
6+
// The cleanup cancels the timer when the page is closed (during prerender),
7+
// so the redirect only fires for real visitors.
8+
const t = setTimeout(() => {
9+
window.location.href = '/sitemap.xml';
10+
}, 1500);
11+
return () => clearTimeout(t);
12+
}, []);
13+
14+
return (
15+
<div className="p-10 text-center text-white text-xl">
16+
<h1>
17+
Redirecting to{' '}
18+
<a href="/sitemap.xml" className="underline">
19+
sitemap.xml
20+
</a>
21+
...
22+
</h1>
23+
</div>
24+
);
25+
};
26+
27+
export default SitemapPage;

0 commit comments

Comments
 (0)