Preview: Serve footer destinations at directory URLs. - #5
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The audit script currently computes internal target paths incorrectly (dropping dist), and the rewrite plugin doesn’t apply to vite preview without a preview-server hook.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Ensures local navigation to prerendered “footer destination” pages works by rewriting directory URLs to their corresponding index.html files during local serving, and adds automated checks around those routes and footer link targets.
Changes:
- Add a Vite plugin that rewrites requests like
/privacy/→/privacy/index.html. - Add a local-server integration test covering the affected routes.
- Extend the site audit script to validate footer link destinations/anchors across generated pages.
File summaries
| File | Description |
|---|---|
| vite.config.ts | Registers the new static-page rewrite plugin alongside React. |
| scripts/static-pages.ts | Implements middleware that rewrites specific directory URLs to index.html. |
| tests/static-pages.test.mjs | Adds an integration test that exercises the rewrite behavior via a local Vite server. |
| scripts/audit-site.mjs | Adds footer destination/link-target validation to the build audit. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+100
to
+103
| } | ||
| const target = path.join(dist, destination.pathname, "index.html"); | ||
| const targetHtml = await readFile(target, "utf8"); | ||
| if (destination.hash) assert.ok(targetHtml.includes(`id="${destination.hash.slice(1)}"`), `Missing footer anchor ${href}`); |
Comment on lines
+4
to
+20
| export function staticPages(): Plugin { | ||
| return { | ||
| name: "pasted-static-pages", | ||
| configureServer(server) { | ||
| server.middlewares.use((request, _response, next) => { | ||
| const incoming = request as { url?: string }; | ||
| if (incoming.url) { | ||
| incoming.url = incoming.url.replace( | ||
| /^\/(features|download|cli|privacy|thanks)\/?(?=\?|$)/, | ||
| "/$1/index.html", | ||
| ); | ||
| } | ||
| next(); | ||
| }); | ||
| }, | ||
| }; | ||
| } |
Comment on lines
+6
to
+16
| import { createServer } from "vite"; | ||
| import { staticPages } from "../scripts/static-pages.ts"; | ||
|
|
||
| test("preview directory links serve their own pages instead of the SPA homepage", async () => { | ||
| const cacheDir = await mkdtemp(path.join(tmpdir(), "pasted-preview-test-")); | ||
| const server = await createServer({ | ||
| cacheDir, | ||
| configFile: false, | ||
| plugins: [staticPages()], | ||
| server: { host: "127.0.0.1", port: 0 }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix local footer navigation: Vite now serves the static Features, Download, CLI, Privacy, and Thanks pages at their directory URLs instead of falling back to the homepage.
Add a preview integration test with a separate temporary dependency cache so tests cannot disrupt the running preview. Audit every generated footer's local page and anchor targets.
Validation: npm test; git diff --check; browser navigation from Home to Privacy and CLI and back after the tests; public footer destinations returned HTTP 200.