{"record":{"id":"53bf5c101c17e861","repo":"nocobase/nocobase","slug":"popup-template-not-found-53bf5c","errorCode":null,"errorMessage":"Popup template not found","messagePattern":"Popup template not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/plugins/@nocobase/plugin-ui-templates/src/client-v2/openViewActionExtensions.tsx","lineNumber":909,"sourceCode":"      onPopupScroll={(e) => {\n        const target = e?.target as HTMLElement | undefined;\n        if (!target) return;\n        if (target.scrollTop + target.clientHeight < target.scrollHeight - 24) return;\n        loadMore();\n      }}\n      dropdownMatchSelectWidth\n      getPopupContainer={() => document.body}\n      optionRender={renderTemplateSelectOption}\n    />\n  );\n}\n\nconst resolveTemplateToUid = async (ctx: FlowSettingsContext, params: any): Promise<void> => {\n  const templateUid = typeof params?.popupTemplateUid === 'string' ? params.popupTemplateUid.trim() : '';\n  if (!templateUid) return;\n  const tpl = await fetchTemplateByUid(ctx as any, templateUid);\n  if (!tpl?.targetUid) {\n    throw new Error(tWithNs(ctx, 'Popup template not found'));\n  }\n\n  const expected = resolveExpectedResourceInfo(ctx as any, params);\n  const expectedSource = resolveExpectedSourceResourceInfo(ctx as any, params);\n  const disabledReason = await getPopupTemplateDisabledReason(ctx as any, tpl, expected, expectedSource, params);\n  if (disabledReason) {\n    throw new Error(disabledReason);\n  }\n\n  params.uid = tpl.targetUid;\n  // collectionName / associationName / dataSourceKey 以模板为准（associationName 允许为空表示\"非关系弹窗\"）\n  const tplDataSourceKey = normalizeStr(tpl?.dataSourceKey);\n  const tplCollectionName = normalizeStr(tpl?.collectionName);\n  const tplAssociationName = normalizeStr(tpl?.associationName);\n  if (tplDataSourceKey) {\n    params.dataSourceKey = tplDataSourceKey;\n  }\n  if (tplCollectionName) {","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/plugins/@nocobase/plugin-ui-templates/src/client-v2/openViewActionExtensions.tsx#L891-L927","documentation":"resolveTemplateToUid in openViewActionExtensions resolves a popupTemplateUid parameter to the template's underlying popup model uid before opening the popup. It fetches the flowModelTemplates row by uid; if the row is missing or has no targetUid, it throws this localized error because there is no popup to open. Subsequently a resource-match check runs, but this specific throw happens first for the missing/malformed template.","triggerScenarios":"An open-view action configured with params.popupTemplateUid whose template row was deleted from flowModelTemplates, or whose targetUid is null/empty — e.g. the referenced popup template was removed by another user, an import/migration dropped rows, or the uid string is stale after a schema reset.","commonSituations":"Sharing actions/pages between environments where template uids don't exist in the target database; deleting a popup template that is still referenced by menu/open-view actions; restoring a backup where flowModelTemplates rows were not included; typos when setting popupTemplateUid manually in action params.","solutions":["Re-create the popup template (or re-link the action) so popupTemplateUid points to an existing flowModelTemplates row with a non-empty targetUid.","Check the flowModelTemplates table/collection for the uid and restore or fix the row's targetUid.","Remove or repoint the popupTemplateUid param on the open-view action if the template is intentionally gone.","When migrating environments, export/import template rows together with the schemas that reference them."],"exampleFix":"// before: action params reference a deleted template\nparams: { popupTemplateUid: 'tpl-gone' } // -> throws 'Popup template not found'\n// after: point at an existing template\nparams: { popupTemplateUid: 'tpl-123' }","handlingStrategy":"validation","validationCode":"// before opening a popup that uses a template\nconst tpl = await api.resource('flowModelTemplates').get({ filterByTk: templateId });\nif (!tpl?.data?.targetUid) {\n  // template missing or dangling — re-link or recreate before the action runs\n  return message.error('Referenced popup template no longer exists.');\n}","typeGuard":"function isLiveTemplate(tpl: unknown): tpl is { targetUid: string } {\n  return !!tpl && typeof (tpl as any).targetUid === 'string' && (tpl as any).targetUid.length > 0;\n}","tryCatchPattern":"try {\n  await openViewWithTemplate(ctx, params);\n} catch (e) {\n  if (e.message === 'Popup template not found') {\n    // offer to recreate the template or strip popupTemplateUid from params\n  } else throw e;\n}","preventionTips":["Keep flowModelTemplates rows in sync across environments when exporting actions.","Clean up actions referencing a template before deleting it.","Validate popupTemplateUid values set manually in action params."],"tags":["ui-templates","open-view","popup-template","missing-record"],"backgroundTag":"template-missing-target-uid","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}