fix: support /god-mode route without trailing slash (#9068)#9070
fix: support /god-mode route without trailing slash (#9068)#9070rishipandey2 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe admin app now uses a new ChangesAdmin base path normalization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
apps/admin/vite.config.ts (1)
17-20: ⚡ Quick winAvoid normalization drift between Vite and React Router configs.
This block duplicates the same base-path logic from
apps/admin/react-router.config.ts. Extracting a sharednormalizeBasePathhelper keeps both layers in lockstep and prevents regressions from future one-sided edits.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/admin/vite.config.ts` around lines 17 - 20, Extract the base-path normalization into a shared function named normalizeBasePath that implements the existing logic (treat raw "" or "/" as "/", otherwise strip trailing slashes with raw.replace(/\/+$/, "")); replace the inline logic in apps/admin/vite.config.ts (the const rawBasePath / basePath block) and in apps/admin/react-router.config.ts to call normalizeBasePath(rawBasePath) so both configs import and use the same helper and stay in sync.apps/admin/react-router.config.ts (1)
3-5: ⚡ Quick winHarden base path normalization for slash-only and no-leading-slash inputs.
On
Line 5, values like"////"normalize to"", and"god-mode/"normalizes to"god-mode"(no leading slash). Normalizing these to an absolute path shape avoids fragile env-dependent behavior.Proposed change
-const rawBasePath = process.env.VITE_ADMIN_BASE_PATH ?? ""; - -const basePath = rawBasePath === "/" || rawBasePath === "" ? "/" : rawBasePath.replace(/\/+$/, ""); +const normalizeBasePath = (rawBasePath: string): string => { + const trimmed = rawBasePath.trim(); + if (trimmed === "" || /^\/+$/.test(trimmed)) return "/"; + const withoutTrailingSlashes = trimmed.replace(/\/+$/, ""); + return withoutTrailingSlashes.startsWith("/") ? withoutTrailingSlashes : `/${withoutTrailingSlashes}`; +}; + +const basePath = normalizeBasePath(process.env.VITE_ADMIN_BASE_PATH ?? "");🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/admin/react-router.config.ts` around lines 3 - 5, The basePath normalization is fragile for inputs like "////" or "god-mode/"; update the logic around rawBasePath/basePath to first collapse repeated slashes, then strip trailing slashes (but preserve a single leading slash), and if the resulting path is empty or only slashes, set basePath to "/". Concretely: normalize rawBasePath by replacing multiple consecutive slashes with one, remove any trailing slash(es) except the leading one, and ensure the final basePath always starts with a "/" (falling back to "/" for empty results).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/admin/react-router.config.ts`:
- Around line 3-5: The basePath normalization is fragile for inputs like "////"
or "god-mode/"; update the logic around rawBasePath/basePath to first collapse
repeated slashes, then strip trailing slashes (but preserve a single leading
slash), and if the resulting path is empty or only slashes, set basePath to "/".
Concretely: normalize rawBasePath by replacing multiple consecutive slashes with
one, remove any trailing slash(es) except the leading one, and ensure the final
basePath always starts with a "/" (falling back to "/" for empty results).
In `@apps/admin/vite.config.ts`:
- Around line 17-20: Extract the base-path normalization into a shared function
named normalizeBasePath that implements the existing logic (treat raw "" or "/"
as "/", otherwise strip trailing slashes with raw.replace(/\/+$/, "")); replace
the inline logic in apps/admin/vite.config.ts (the const rawBasePath / basePath
block) and in apps/admin/react-router.config.ts to call
normalizeBasePath(rawBasePath) so both configs import and use the same helper
and stay in sync.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a334fcb5-3736-4caa-a0c8-4dbd967111e2
📒 Files selected for processing (2)
apps/admin/react-router.config.tsapps/admin/vite.config.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/utils/src/string.ts`:
- Around line 435-451: Add a JSDoc block above the exported function
normalizeBasePath describing its purpose, include `@description` that explains it
normalizes a raw base path to a canonical URL path (empty or slash-only => "/",
collapse multiple slashes, remove trailing slashes except root, ensure leading
slash), add `@param` {string} rawBasePath explanation, add `@returns` {string}
describing the normalized path, and include an `@example` showing typical inputs
and outputs (e.g. "", "/", "///api//v1/", "api/v1" ->
"/","/","/api/v1","/api/v1"). Ensure the JSDoc follows the same style and tags
used by other exported functions in this file.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6e8a8a27-b60e-4c55-94aa-e886029c81d0
📒 Files selected for processing (3)
apps/admin/react-router.config.tsapps/admin/vite.config.tspackages/utils/src/string.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/admin/react-router.config.ts
Closes #9068
Summary
Fixes an issue where accessing
/god-modewithout a trailing slash caused the admin app to render a blank/loading page.Root Cause
The admin router basename and Vite base path were configured with a trailing slash (
/god-mode/), causing React Router to fail matching requests to/god-mode.Changes
Normalized the admin base path configuration to consistently remove trailing slashes for:
Testing
Verified that:
/god-moderenders correctly/god-mode/renders correctlySummary by CodeRabbit