[fix] repair Open Library borrowing page rendering#94
Merged
Conversation
Preserve translation resolver functions across SSR serialization and render paragraph Markdown inline to prevent runtime and hydration errors.
📝 WalkthroughWalkthroughChangesSSR 国际化数据序列化
远程图书详情加载
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant NextSSR
participant loadSSRLanguage
participant loadLanguageMapFrom
participant createI18nStore
NextSSR->>loadSSRLanguage: 请求 SSR 语言数据
loadSSRLanguage->>loadLanguageMapFrom: 异步加载语言映射
loadLanguageMapFrom-->>loadSSRLanguage: 返回语言映射
loadSSRLanguage-->>NextSSR: 返回序列化 languageMap
NextSSR->>createI18nStore: 传入 serializedData
createI18nStore->>createI18nStore: 使用 decodeFunctions 解析数据
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
TechQuery
approved these changes
Jul 15, 2026
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pages/open-library/book/[id].tsx (1)
19-24: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win优化类型转换并避免潜在的 SSR 性能反模式
针对这段数据获取代码,建议进行以下优化以符合现代 TypeScript 规范并保障服务端性能:
- 类型转换与可选链:
+(params!.id + '')的写法较为晦涩,建议使用更符合现代 ECMAScript 规范的Number(params?.id);同时对于接口响应的body推荐使用可选链body?.find,以替代非空断言!,避免因网络或解构异常导致的运行时崩溃。- Pages Router 数据获取正确性:在
getServerSideProps中直接请求自身的 API 路由(即${API_Host}/api/...)是 Next.js 官方明确指出的性能反模式,这会在同服务器内增加额外的 HTTP 往返开销。如果这是当前项目的内部路由,建议直接提取并复用底层的获取逻辑;如果此处仅是作为后端真实接口上线前的临时 Mock,则可忽略此架构提示。💡 推荐的重构代码
- const bookId = +(params!.id + ''); - - const { body } = await larkClient.get<Book[]>(`${API_Host}/api/open-library/books`); - - const book = body!.find(({ id }) => id === bookId); + const bookId = Number(params?.id); + + const { body } = await larkClient.get<Book[]>(`${API_Host}/api/open-library/books`); + + const book = body?.find(({ id }) => id === bookId);🤖 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 `@pages/open-library/book/`[id].tsx around lines 19 - 24, 更新 getServerSideProps 中的类型转换,使用 Number(params?.id) 替代当前的字符串拼接与非空断言;将 body!.find 改为通过可选链安全查找。若该接口是项目内部 API,提取并复用底层数据获取逻辑,避免 SSR 通过 HTTP 请求自身的 API 路由;若是临时 Mock,则保留现有请求方式。Source: Coding guidelines
🤖 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 `@pages/open-library/book/`[id].tsx:
- Around line 19-24: 更新 getServerSideProps 中的类型转换,使用 Number(params?.id)
替代当前的字符串拼接与非空断言;将 body!.find 改为通过可选链安全查找。若该接口是项目内部 API,提取并复用底层数据获取逻辑,避免 SSR 通过
HTTP 请求自身的 API 路由;若是临时 Mock,则保留现有请求方式。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4009c373-4fe6-4b52-9516-c866748e46c6
📒 Files selected for processing (2)
models/Translation.tspages/open-library/book/[id].tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- models/Translation.ts
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.
Preserve translation resolver functions across SSR serialization and render paragraph Markdown inline to prevent runtime and hydration errors.
Checklist(清单):
Closes
Summary by CodeRabbit
新功能
错误修复