延后资源草稿直到素材索引可用

避免初始编辑器挂载时 assetsById 为空导致资源引用永久丢失。

保留 Lexical 节点自行解析资产名称的后续 TODO。
This commit is contained in:
2026-09-18 12:53:44 +08:00
parent 4ae5ab14fa
commit 6e63a118e0
@@ -726,6 +726,20 @@ function ResourceReferenceEditor({
if (initialDraftAppliedRef.current || !initialContent) {
return;
}
// Manifest assets can arrive after the initial editor mount. Do not mark the
// draft as applied while resource references still have no lookup table;
// otherwise the later assetsById update cannot restore those references.
const hasUnresolvedResourceReference = initialContent.some(
(part) =>
part.type === 'agc_resource_reference' &&
!assetsById.has(part.resourceId),
);
if (hasUnresolvedResourceReference && assetsById.size === 0) {
return;
}
// TODO: let the Lexical resource node resolve its asset label from the
// manifest itself, so unresolved references can remain as nodes while the
// manifest loads instead of waiting in this effect.
initialDraftAppliedRef.current = true;
editor.update(() => {
applyContentToRoot(initialContent, assetsById);