Feat/url id query and type module#767
Conversation
WalkthroughThis PR systematically converts the project from CommonJS and inconsistent module patterns to strict ES modules (ESM). It adds ChangesES Module System Conversion and Post ID Redirection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 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.
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 `@theme/layout/index.tsx`:
- Around line 71-80: The current matching logic for normalizedPostId can return
a post from any locale because the fallback postInfos.find(...) ignores
page.lang; change this by first collecting candidates where
normalizePostId(post.id) === normalizedPostId, then set matchedPost to the
candidate that also matches page.lang if present, otherwise only use the single
candidate when candidates.length === 1; update the code around normalizedPostId
/ matchedPost / postInfos / normalizePostId to implement this
conditional-fallback behavior so you never redirect to an arbitrary locale when
multiple candidates exist.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4248c345-f45a-4132-8976-2cb4aa7b9792
📒 Files selected for processing (13)
doom.config.tspackage.jsonplugins/plugin-post-resolver/BlogPostResolver.tsplugins/plugin-post-resolver/PostData.tsplugins/plugin-post-resolver/index.tspostcss.config.jstheme/components/HomeContent/index.tsxtheme/components/PostList/index.tsxtheme/components/SidebarMenu/index.tstheme/index.tsxtheme/layout/DocLayout/index.tsxtheme/layout/HomeLayout/index.tsxtheme/layout/index.tsx
| if (normalizedPostId) { | ||
| const matchedPost = | ||
| postInfos.find( | ||
| (post) => | ||
| normalizePostId(post.id) === normalizedPostId && | ||
| post.locale === page.lang | ||
| ) || | ||
| postInfos.find( | ||
| (post) => normalizePostId(post.id) === normalizedPostId | ||
| ); |
There was a problem hiding this comment.
Avoid redirecting to an arbitrary locale on fallback.
If the same id exists in multiple locales, the second find() ignores page.lang and can send users to the wrong language variant. A safer fallback is to ignore locale only when there is exactly one candidate for that id.
Suggested fix
- if (normalizedPostId) {
- const matchedPost =
- postInfos.find(
- (post) =>
- normalizePostId(post.id) === normalizedPostId &&
- post.locale === page.lang
- ) ||
- postInfos.find(
- (post) => normalizePostId(post.id) === normalizedPostId
- );
+ if (normalizedPostId) {
+ const candidates = postInfos.filter(
+ (post) => normalizePostId(post.id) === normalizedPostId
+ );
+ const matchedPost =
+ candidates.find((post) => post.locale === page.lang) ??
+ (candidates.length === 1 ? candidates[0] : undefined);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (normalizedPostId) { | |
| const matchedPost = | |
| postInfos.find( | |
| (post) => | |
| normalizePostId(post.id) === normalizedPostId && | |
| post.locale === page.lang | |
| ) || | |
| postInfos.find( | |
| (post) => normalizePostId(post.id) === normalizedPostId | |
| ); | |
| if (normalizedPostId) { | |
| const candidates = postInfos.filter( | |
| (post) => normalizePostId(post.id) === normalizedPostId | |
| ); | |
| const matchedPost = | |
| candidates.find((post) => post.locale === page.lang) ?? | |
| (candidates.length === 1 ? candidates[0] : undefined); |
🤖 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 `@theme/layout/index.tsx` around lines 71 - 80, The current matching logic for
normalizedPostId can return a post from any locale because the fallback
postInfos.find(...) ignores page.lang; change this by first collecting
candidates where normalizePostId(post.id) === normalizedPostId, then set
matchedPost to the candidate that also matches page.lang if present, otherwise
only use the single candidate when candidates.length === 1; update the code
around normalizedPostId / matchedPost / postInfos / normalizePostId to implement
this conditional-fallback behavior so you never redirect to an arbitrary locale
when multiple candidates exist.
Summary by CodeRabbit
New Features
Chores