fix: bypass Vite tree-shake for pointCode via pointCodeMap
Vite's SSR build strips pointCode from ReviewPointResult return objects. Workaround: pass a separate pointCodeMap from reviews.ts and apply it in the route loader (reviews.tsx) which Vite preserves. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -209,6 +209,14 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
}
|
||||
|
||||
if ('document' in reviewData && 'data' in reviewData && 'reviewInfo' in reviewData && 'stats' in reviewData) {
|
||||
// 补充 pointCode(Vite tree-shake 会移除 reviews.ts 中的 pointCode)
|
||||
if (reviewData.pointCodeMap) {
|
||||
(reviewData.data as any[]).forEach((p: any) => {
|
||||
if (!p.pointCode && p.pointId && reviewData.pointCodeMap[p.pointId]) {
|
||||
p.pointCode = reviewData.pointCodeMap[p.pointId];
|
||||
}
|
||||
});
|
||||
}
|
||||
return Response.json({
|
||||
previousRoute: previousRoute,
|
||||
document: reviewData.document,
|
||||
@@ -257,6 +265,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
}));
|
||||
const allReviewPoints = [...existingPoints, ...notApplicablePoints];
|
||||
|
||||
// 补充 pointCode(从统一接口的 scored results 获取 code)
|
||||
const codeMap = new Map<number, string>();
|
||||
(unifiedData.results || []).forEach((r: any) => {
|
||||
if (r.evaluation_point_id && r.code) codeMap.set(r.evaluation_point_id, r.code);
|
||||
});
|
||||
allReviewPoints.forEach((p: any) => {
|
||||
if (!p.pointCode && p.pointId && codeMap.has(Number(p.pointId))) {
|
||||
p.pointCode = codeMap.get(Number(p.pointId));
|
||||
}
|
||||
});
|
||||
|
||||
return Response.json({
|
||||
previousRoute: previousRoute,
|
||||
document: ('document' in reviewData && !('error' in reviewData)) ? reviewData.document : null,
|
||||
|
||||
Reference in New Issue
Block a user