Fix stuck segments tab; add /segments/ dev fallback
AthleteView: use segmentsFetched flag to prevent infinite fetch loop when
there are no efforts (segmentSummary.length === 0 was re-triggering the
reactive statement after every empty response). Also improve empty state
message and reset flag after rescan so the table reloads.
astro.config.mjs: extend shell fallback plugin to cover /segments/{id}/
the same way /activity/{id}/ is handled, so segment detail pages work in
the dev server without nginx.
This commit is contained in:
+10
-5
@@ -9,15 +9,20 @@ const env = loadEnv(process.env.NODE_ENV ?? 'development', process.cwd(), '');
|
||||
const apiPort = process.env.VITE_API_PORT || '4041';
|
||||
const serveTarget = env.PUBLIC_EDIT_URL || `http://localhost:${apiPort}`;
|
||||
|
||||
// In production, nginx serves activity/index.html for all /activity/<id>/ URLs
|
||||
// via try_files. In dev (Astro dev server), no nginx — this plugin replicates it.
|
||||
const activityFallbackPlugin = {
|
||||
name: 'activity-shell-fallback',
|
||||
// In production, nginx serves the shell for dynamic sub-paths via try_files.
|
||||
// In dev (Astro dev server), no nginx — this plugin replicates those rules.
|
||||
const shellFallbackPlugin = {
|
||||
name: 'shell-fallback',
|
||||
configureServer(server) {
|
||||
server.middlewares.use((req, _res, next) => {
|
||||
if (req.url && /^\/activity\/[^/]+\/?(\?|$)/.test(req.url)) {
|
||||
req.url = '/activity/';
|
||||
}
|
||||
// /segments/{id}/ → /segments/ (but not /segments/new/ which has its own page)
|
||||
const segMatch = req.url?.match(/^\/segments\/([^/?]+)\//);
|
||||
if (segMatch && segMatch[1] !== 'new') {
|
||||
req.url = '/segments/';
|
||||
}
|
||||
next();
|
||||
});
|
||||
},
|
||||
@@ -30,7 +35,7 @@ export default defineConfig({
|
||||
// When hosting at a subdirectory (e.g. GitHub Pages project site), set:
|
||||
// base: "/repo-name",
|
||||
vite: {
|
||||
plugins: [activityFallbackPlugin],
|
||||
plugins: [shellFallbackPlugin],
|
||||
optimizeDeps: {
|
||||
include: ['maplibre-gl'],
|
||||
esbuildOptions: { target: 'es2022' },
|
||||
|
||||
Reference in New Issue
Block a user