[Bug] 刚上传的模板立即选用报「模板加载失败」:getTemplateFile 只查调用方传入的过期列表
Author: zgybkjcn-a11yCreated Sep 12, 2026Updated Sep 12, 2026
Deployment Method / 部署方式
Docker Compose (docker-compose.yml)
Issue Description / 问题描述
frontend/src/components/shared/TemplateSelector.tsx 的 getTemplateFile(templateId, userTemplates) 只在调用方传入的 userTemplates 列表里查找模板:
const userTemplate = userTemplates.find(t => t.template_id === templateId);但这个列表可能过期:用户刚上传了一个新模板,马上用它生成 PPT,而调用方(Home.tsx / SlidePreview.tsx)的 state 还没同步到这条新模板。查找落空 → getTemplateFile 返回 null → 用户看到「模板加载失败」报错,尽管模板明明存在、后端也能查到。
Steps to Reproduce / 复现步骤
- 素材库里上传一个新模板
- 不刷新页面、不重新打开模板选择器(调用方 state 未同步)
- 直接选该模板生成 PPT
- 报「模板加载失败」,虽然模板刚上传成功
Expected Behavior / 期望行为
传入列表未命中时,从后端拉一次最新用户模板列表兜底,而不是直接失败。
建议修复
let userTemplate = userTemplates.find(t => t.template_id === templateId);
if (!userTemplate) {
try {
const response = await listUserTemplates();
userTemplate = response.data?.templates?.find(t => t.template_id === templateId);
} catch (error) {
console.error('Failed to refresh user templates:', error);
}
}命中失败才返回 null。已开 PR(含单测覆盖该恢复路径),见下方链接。
Version / 版本
main (199cf9e);v0.9.0-rc.7 同样存在
Source: Anionex/banana-slides