Skip to content

Commit

Permalink
fix: ensure placeholder is hidden (#82)
Browse files Browse the repository at this point in the history
related: #41 #45 #64
  • Loading branch information
u3u authored Mar 18, 2021
1 parent 10cb4ca commit 75a1764
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const ImageInternal: CompoundedComponent<ImageProps> = ({
});
const canPreview = preview && !isError;

const isLoaded = React.useRef(false);

const onLoad = () => {
setStatus('normal');
};
Expand Down Expand Up @@ -157,8 +159,10 @@ const ImageInternal: CompoundedComponent<ImageProps> = ({
};

const getImgRef = (img?: HTMLImageElement) => {
isLoaded.current = false;
if (status !== 'loading') return;
if (img?.complete && (img.naturalWidth || img.naturalHeight)) {
isLoaded.current = true;
onLoad();
}
};
Expand All @@ -185,7 +189,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = ({
if (isError) {
setStatus('normal');
}
if (isCustomPlaceholder) {
if (isCustomPlaceholder && !isLoaded.current) {
setStatus('loading');
}
}, [imgSrc]);
Expand Down
8 changes: 0 additions & 8 deletions tests/placeholder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ describe('Placeholder', () => {
/>,
);

expect(wrapper.find('.rc-image-placeholder').get(0)).toBeTruthy();

act(() => {
wrapper.setProps({});
jest.runAllTimers();
wrapper.update();
});

expect(wrapper.find('.rc-image-placeholder').get(0)).toBeFalsy();

domSpy.mockRestore();
Expand Down

1 comment on commit 75a1764

@vercel
Copy link

@vercel vercel bot commented on 75a1764 Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.