Skip to content

Commit

Permalink
Fix how file data is cached and restored.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaehring committed Jul 17, 2023
1 parent b9589ed commit 7ff172d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/field-kit/src/entities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,11 @@ export default function useEntities(options = {}) {
const getResources = state => state?.relationships?.[field] || [];
revision.queue.push(refState => Promise.all(getResources(refState).map(async (resource) => {
const init = await loadFileEntity(resource);
const fileData = init === null ? fmtFileData(null, null, resource) : init;
const file = useFile(fileData);
let fileData = init === null ? fmtFileData(null, null, resource) : init;
let file = useFile(fileData);
upsert(revision.files[field], 'id', file);
revision.files[field].push(file);
if (init === null) return cacheFileData(null, null, resource);
return fileData;
})).then(async (fileData) => {
if (init === null) fileData = await cacheFileData(null, null, resource);
if (validate(fileData.file_entity?.id)) return fileData;
// Normally the fileData's id and type can't be assumed to be the same as
// the file_entity, but if there's no file_entity, then we can be sure the
Expand All @@ -461,10 +459,10 @@ export default function useEntities(options = {}) {
headers, responseType: 'blob', url,
});
const updated = fmtFileData(data, file_entity, { id, type });
const file = useFile(updated);
file = useFile(updated);
upsert(revision.files[field], 'id', file);
return cacheFileData(data, file_entity, { id, type });
}).then(() => refState).catch(() => refState));
})).then(() => refState).catch(() => refState));

return readonly(revision.files[field]);
}
Expand Down

0 comments on commit 7ff172d

Please sign in to comment.