Skip to content

Commit

Permalink
util/data.js: omit exposed image resolver configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnito committed Feb 7, 2023
1 parent be8d481 commit 9a8accc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/util/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,18 @@ const denormalizeJsonData = (data, included) => {
value._ref &&
value._ref?.type === 'imageAsset' &&
value._ref?.id;
// If there is no image included,
// the _ref might contain parameters for image resolver (Asset Delivery API resolves image URLs on the fly)
const hasUnresolvedImageRef =
typeof value == 'object' && value._ref && value._ref?.resolver === 'image';

if (hasImageRefAsValue) {
const foundRef = included.find(inc => inc.id === value._ref?.id);
copy[key] = foundRef;
} else if (hasUnresolvedImageRef) {
// Don't add faulty image ref
// Note: At the time of writing, assets can expose resolver configs,
// which we don't want to deal with.
} else {
copy[key] = denormalizeJsonData(value, included);
}
Expand Down

0 comments on commit 9a8accc

Please sign in to comment.