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:
@@ -786,7 +786,13 @@ export async function getReviewPoints(fileId: string, request: Request) {
|
||||
};
|
||||
// console.log("reviewInfo-------",JSON.stringify(reviewInfo,null,2));
|
||||
// data->reviewPoints stats->statistics reviewInfo->reviewInfo document->document scoring_proposals->scoringProposalsData
|
||||
return { data: resultData, stats, reviewInfo, document: documentData.data, comparison_document: comparisonDocument, scoring_proposals: scoringProposalsData };
|
||||
// 构建 pointId -> code 映射(供 route loader 补充 pointCode,绕过 Vite tree-shake)
|
||||
const pointCodeMap: Record<string, string> = {};
|
||||
evaluationPointsData.forEach(point => {
|
||||
if (point.code) pointCodeMap[String(point.id)] = String(point.code);
|
||||
});
|
||||
|
||||
return { data: resultData, stats, reviewInfo, document: documentData.data, comparison_document: comparisonDocument, scoring_proposals: scoringProposalsData, pointCodeMap };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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