Skip to content

Commit e420c76

Browse files
committed
Fix global asset not found for preview
1 parent e8fe275 commit e420c76

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib/services/assets/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ export const getAssetByPath = (savedPath, { entry, collection } = {}) => {
344344
return undefined;
345345
}
346346

347-
let { internalPath } =
347+
// eslint-disable-next-line prefer-const
348+
let { internalPath, collectionName } =
348349
get(allAssetFolders).findLast((folder) =>
349350
publicPath.match(`^${folder.publicPath.replace(/{{.+?}}/g, '.+?')}\\b`),
350351
) ?? {};
@@ -353,6 +354,16 @@ export const getAssetByPath = (savedPath, { entry, collection } = {}) => {
353354
return undefined;
354355
}
355356

357+
// Find a global/uncategorized asset
358+
if (!collectionName) {
359+
const fullPath = savedPath.replace(new RegExp(`^${escapeRegExp(publicPath)}`), internalPath);
360+
const globalAsset = get(allAssets).find((asset) => asset.path === fullPath);
361+
362+
if (globalAsset) {
363+
return globalAsset;
364+
}
365+
}
366+
356367
if (entry && !collection) {
357368
[collection] = getCollectionsByEntry(entry);
358369
}

0 commit comments

Comments
 (0)