Skip to content

Commit 26c1ae9

Browse files
committed
Don't raise load events for the default (fallback) source
1 parent d90e85c commit 26c1ae9

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

packages/react-native-web/src/exports/Image/__tests__/__snapshots__/index-test.js.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,14 @@ exports[`components/Image prop "style" removes other unsupported View styles 1`]
329329
>
330330
<div
331331
class="css-view-175oi2r r-backgroundColor-1niwhzg r-backgroundPosition-vvn4in r-backgroundRepeat-u6sd8q r-bottom-1p0dtai r-height-1pi2tsx r-left-1d2f490 r-position-u8s1d r-right-zchlnj r-top-ipm5af r-width-13qz1uu r-zIndex-1wyyakw r-backgroundSize-4gszlv"
332-
style="filter: url(#tint-96);"
332+
style="filter: url(#tint-98);"
333333
/>
334334
<svg
335335
style="position: absolute; height: 0px; visibility: hidden; width: 0px;"
336336
>
337337
<defs>
338338
<filter
339-
id="tint-96"
339+
id="tint-98"
340340
>
341341
<feflood
342342
flood-color="blue"
@@ -378,7 +378,7 @@ exports[`components/Image prop "style" supports "tintcolor" property (convert to
378378
>
379379
<div
380380
class="css-view-175oi2r r-backgroundColor-1niwhzg r-backgroundPosition-vvn4in r-backgroundRepeat-u6sd8q r-bottom-1p0dtai r-height-1pi2tsx r-left-1d2f490 r-position-u8s1d r-right-zchlnj r-top-ipm5af r-width-13qz1uu r-zIndex-1wyyakw r-backgroundSize-4gszlv"
381-
style="background-image: url(https://google.com/favicon.ico); filter: url(#tint-94);"
381+
style="background-image: url(https://google.com/favicon.ico); filter: url(#tint-96);"
382382
/>
383383
<img
384384
alt=""
@@ -391,7 +391,7 @@ exports[`components/Image prop "style" supports "tintcolor" property (convert to
391391
>
392392
<defs>
393393
<filter
394-
id="tint-94"
394+
id="tint-96"
395395
>
396396
<feflood
397397
flood-color="red"

packages/react-native-web/src/exports/Image/__tests__/index-test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,33 @@ describe('components/Image', () => {
294294
expect(onLoadStub.mock.calls.length).toBe(1);
295295
expect(onLoadEndStub.mock.calls.length).toBe(1);
296296
});
297+
298+
test('is not called for default source', () => {
299+
jest.useFakeTimers();
300+
const onLoadStartStub = jest.fn();
301+
const onLoadStub = jest.fn();
302+
const onLoadEndStub = jest.fn();
303+
render(
304+
<Image
305+
defaultSource="https://test.com/img-2.jpg"
306+
onLoad={onLoadStub}
307+
onLoadEnd={onLoadEndStub}
308+
onLoadStart={onLoadStartStub}
309+
source="https://test.com/img.jpg"
310+
/>
311+
);
312+
jest.runOnlyPendingTimers();
313+
expect(onLoadStub).toHaveBeenCalledTimes(1);
314+
expect(onLoadStub).toHaveBeenCalledWith(
315+
expect.objectContaining({
316+
nativeEvent: {
317+
source: {
318+
uri: 'https://test.com/img.jpg'
319+
}
320+
}
321+
})
322+
);
323+
});
297324
});
298325

299326
describe('prop "resizeMode"', () => {

packages/react-native-web/src/exports/Image/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,12 @@ const Image: React.AbstractComponent<
212212
}
213213
}
214214

215-
const imageLoadingProps = { onLoad, onLoadStart, onLoadEnd, onError };
216-
217-
const fallbackSource = useSource(imageLoadingProps, defaultSource);
218-
const mainSource = useSource(imageLoadingProps, source);
215+
// Don't raise load events from the fallback source
216+
const fallbackSource = useSource({ onError }, defaultSource);
217+
const mainSource = useSource(
218+
{ onLoad, onLoadStart, onLoadEnd, onError },
219+
source
220+
);
219221
const availableSource = getSourceToDisplay(mainSource, fallbackSource);
220222
const displayImageUri = ImageLoader.resolveUri(availableSource.uri);
221223
const imageSizeStyle = resolveAssetDimensions(availableSource);

0 commit comments

Comments
 (0)