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', () => { it('should return asset with original path on load error', () => {
const path = 'static/media/image.png'; const path = 'static/media/image.png';
const resolvePath = 'resolvePath';
const store = mockStore({ const store = mockStore({
medias: Map({ [path]: { error: true } }), medias: Map({ [resolvePath]: { error: true } }),
}); });
selectMediaFilePath.mockReturnValue(path); selectMediaFilePath.mockReturnValue(resolvePath);
const payload = { path }; const payload = { path };
const result = store.dispatch(getAsset(payload)); const result = store.dispatch(getAsset(payload));
const actions = store.getActions(); 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).toHaveLength(1);
expect(actions[0]).toEqual({ expect(actions[0]).toEqual({
type: ADD_ASSET, type: ADD_ASSET,

View File

@ -114,7 +114,7 @@ export function getAsset({ collection, entry, path, field }: GetAssetArgs) {
} else { } else {
if (error) { if (error) {
// on load error default back to original path // on load error default back to original path
asset = createAssetProxy({ path, url: path }); asset = createAssetProxy({ path: resolvedPath, url: path });
dispatch(addAsset(asset)); dispatch(addAsset(asset));
} else { } else {
dispatch(loadAsset(resolvedPath)); 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) { if (viewStyle === VIEW_STYLE_GRID) {
return ( return (
<GridCard> <GridCard>
@ -116,7 +113,7 @@ const EntryCard = ({
{collectionLabel ? <CollectionLabel>{collectionLabel}</CollectionLabel> : null} {collectionLabel ? <CollectionLabel>{collectionLabel}</CollectionLabel> : null}
<CardHeading>{summary}</CardHeading> <CardHeading>{summary}</CardHeading>
</CardBody> </CardBody>
{image ? <CardImage src={src} /> : null} {image ? <CardImage src={getAsset(image, imageField).toString()} /> : null}
</GridCardLink> </GridCardLink>
</GridCard> </GridCard>
); );