fix: cache assets using resolved path on error (#3378)

This commit is contained in:
Erez Rokah 2020-03-04 15:25:03 +01:00 committed by GitHub
parent ff3b62d12f
commit f3fd43b819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View File

@ -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,

View File

@ -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));

View File

@ -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>
);