fix: cache assets using resolved path on error (#3378)
This commit is contained in:
parent
ff3b62d12f
commit
f3fd43b819
@ -108,17 +108,18 @@ describe('media', () => {
|
||||
|
||||
it('should return asset with original path on load error', () => {
|
||||
const path = 'static/media/image.png';
|
||||
const resolvePath = 'resolvePath';
|
||||
const store = mockStore({
|
||||
medias: Map({ [path]: { error: true } }),
|
||||
medias: Map({ [resolvePath]: { error: true } }),
|
||||
});
|
||||
|
||||
selectMediaFilePath.mockReturnValue(path);
|
||||
selectMediaFilePath.mockReturnValue(resolvePath);
|
||||
const payload = { path };
|
||||
|
||||
const result = store.dispatch(getAsset(payload));
|
||||
const actions = store.getActions();
|
||||
|
||||
const asset = new AssetProxy({ url: path, path });
|
||||
const asset = new AssetProxy({ url: path, path: resolvePath });
|
||||
expect(actions).toHaveLength(1);
|
||||
expect(actions[0]).toEqual({
|
||||
type: ADD_ASSET,
|
@ -114,7 +114,7 @@ export function getAsset({ collection, entry, path, field }: GetAssetArgs) {
|
||||
} else {
|
||||
if (error) {
|
||||
// on load error default back to original path
|
||||
asset = createAssetProxy({ path, url: path });
|
||||
asset = createAssetProxy({ path: resolvedPath, url: path });
|
||||
dispatch(addAsset(asset));
|
||||
} else {
|
||||
dispatch(loadAsset(resolvedPath));
|
||||
|
@ -105,9 +105,6 @@ const EntryCard = ({
|
||||
);
|
||||
}
|
||||
|
||||
const asset = getAsset(image, imageField);
|
||||
const src = asset.toString();
|
||||
|
||||
if (viewStyle === VIEW_STYLE_GRID) {
|
||||
return (
|
||||
<GridCard>
|
||||
@ -116,7 +113,7 @@ const EntryCard = ({
|
||||
{collectionLabel ? <CollectionLabel>{collectionLabel}</CollectionLabel> : null}
|
||||
<CardHeading>{summary}</CardHeading>
|
||||
</CardBody>
|
||||
{image ? <CardImage src={src} /> : null}
|
||||
{image ? <CardImage src={getAsset(image, imageField).toString()} /> : null}
|
||||
</GridCardLink>
|
||||
</GridCard>
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user