Skip to content

Commit 6e2fe92

Browse files
authored
[CLNP-2332] Not to load image if url is empty or null in ImageRenderer (#986)
Fixes: [SBISSUE-15134](https://sendbird.atlassian.net/browse/SBISSUE-15134) ### Changelogs - Fixed `ImageRenderer` not to load image if the source URL is null or empty. [SBISSUE-15134]: https://sendbird.atlassian.net/browse/SBISSUE-15134?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent cb8ef67 commit 6e2fe92

File tree

6 files changed

+20
-36
lines changed

6 files changed

+20
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"react-dom": "^16.8.6 || ^17.0.0 || ^18.0.0"
6868
},
6969
"dependencies": {
70-
"@sendbird/chat": "^4.10.9",
70+
"@sendbird/chat": "^4.10.10",
7171
"@sendbird/uikit-tools": "0.0.1-alpha.62",
7272
"css-vars-ponyfill": "^2.3.2",
7373
"date-fns": "^2.16.1",

src/ui/Avatar/__tests__/__snapshots__/Avatar.spec.js.snap

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ exports[`ui/Avatar should do a snapshot test of the Avatar DOM with four element
5959
>
6060
<div
6161
class="sendbird-image-renderer__image"
62-
style="width: 100%; min-width: min(400px, 56px); max-width: 400px; position: absolute; background-repeat: no-repeat; background-position: center; background-size: cover; background-image: url();"
63-
/>
64-
<img
65-
alt=""
66-
class="sendbird-image-renderer__hidden-image-loader"
67-
src=""
62+
style="width: 100%; min-width: min(400px, 56px); max-width: 400px; position: absolute;"
6863
/>
6964
</div>
7065
</div>
@@ -218,12 +213,7 @@ exports[`ui/Avatar should render default image if src is empty 1`] = `
218213
>
219214
<div
220215
class="sendbird-image-renderer__image"
221-
style="width: 100%; min-width: min(400px, 56px); max-width: 400px; position: absolute; background-repeat: no-repeat; background-position: center; background-size: cover; background-image: url();"
222-
/>
223-
<img
224-
alt=""
225-
class="sendbird-image-renderer__hidden-image-loader"
226-
src=""
216+
style="width: 100%; min-width: min(400px, 56px); max-width: 400px; position: absolute;"
227217
/>
228218
</div>
229219
</div>

src/ui/ImageRenderer/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ const ImageRenderer = ({
9898
};
9999

100100
const renderImage = () => {
101+
const backgroundStyle = internalUrl ? {
102+
backgroundRepeat: 'no-repeat',
103+
backgroundPosition: 'center',
104+
backgroundSize: 'cover',
105+
backgroundImage: `url(${internalUrl})`,
106+
} : {};
107+
101108
return (
102109
<div
103110
className="sendbird-image-renderer__image"
@@ -107,11 +114,8 @@ const ImageRenderer = ({
107114
maxWidth: fixedSize ? dynamicMinWidth : '400px',
108115
height: dynamicMinHeight,
109116
position: 'absolute',
110-
backgroundRepeat: 'no-repeat',
111-
backgroundPosition: 'center',
112-
backgroundSize: 'cover',
113-
backgroundImage: `url(${internalUrl})`,
114117
borderRadius: getBorderRadiusForImageRenderer(circle, borderRadius),
118+
...backgroundStyle,
115119
}}
116120
/>
117121
);
@@ -141,7 +145,7 @@ const ImageRenderer = ({
141145
}}
142146
/>
143147
)}
144-
<HiddenImageLoader
148+
{internalUrl && <HiddenImageLoader
145149
src={internalUrl}
146150
alt={alt}
147151
onLoadStart={() => {
@@ -158,7 +162,7 @@ const ImageRenderer = ({
158162
setDefaultComponentVisible(true);
159163
onError();
160164
}}
161-
/>
165+
/>}
162166
</div>
163167
)
164168
);

src/ui/MessageContent/__tests__/__snapshots__/MessageContent.spec.js.snap

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ exports[`ui/MessageContent should do a snapshot test of the MessageContent DOM 1
2424
>
2525
<div
2626
class="sendbird-image-renderer__image"
27-
style="width: 100%; min-width: min(400px, 28px); max-width: 400px; position: absolute; background-repeat: no-repeat; background-position: center; background-size: cover; background-image: url();"
28-
/>
29-
<img
30-
alt=""
31-
class="sendbird-image-renderer__hidden-image-loader"
32-
src=""
27+
style="width: 100%; min-width: min(400px, 28px); max-width: 400px; position: absolute;"
3328
/>
3429
</div>
3530
</div>

src/ui/OGMessageItemBody/__tests__/__snapshots__/OGMessageItemBody.spec.js.snap

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ exports[`ui/OGMessageItemBody should do a snapshot test of the OGMessageItemBody
2525
>
2626
<div
2727
class="sendbird-image-renderer__image"
28-
style="width: 100%; min-width: min(400px, 100%); max-width: 400px; position: absolute; background-repeat: no-repeat; background-position: center; background-size: cover; background-image: url();"
29-
/>
30-
<img
31-
alt=""
32-
class="sendbird-image-renderer__hidden-image-loader"
33-
src=""
28+
style="width: 100%; min-width: min(400px, 100%); max-width: 400px; position: absolute;"
3429
/>
3530
</div>
3631
</div>

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,15 +2648,15 @@ __metadata:
26482648
languageName: node
26492649
linkType: hard
26502650

2651-
"@sendbird/chat@npm:^4.10.9":
2652-
version: 4.10.9
2653-
resolution: "@sendbird/chat@npm:4.10.9"
2651+
"@sendbird/chat@npm:^4.10.10":
2652+
version: 4.10.10
2653+
resolution: "@sendbird/chat@npm:4.10.10"
26542654
peerDependencies:
26552655
"@react-native-async-storage/async-storage": ^1.17.6
26562656
peerDependenciesMeta:
26572657
"@react-native-async-storage/async-storage":
26582658
optional: true
2659-
checksum: d680ca5aa56dea056aad62a37acc751e0478340638a7cfc0234d5837633aee2a66fee598a27d51157cfddba0f16fceca24cbd5268f9a887a74022d55ca5981da
2659+
checksum: aa84479f4706b6b06befc9ea8121ebd9f456bc1fec57a3fceae5fe713e0a3015224211d2a40c5f0fa9a3b7474987b753f1dcbc151daa39933efb59c685f22824
26602660
languageName: node
26612661
linkType: hard
26622662

@@ -2678,7 +2678,7 @@ __metadata:
26782678
"@rollup/plugin-node-resolve": ^15.2.3
26792679
"@rollup/plugin-replace": ^5.0.4
26802680
"@rollup/plugin-typescript": ^11.1.5
2681-
"@sendbird/chat": ^4.10.9
2681+
"@sendbird/chat": ^4.10.10
26822682
"@sendbird/uikit-tools": 0.0.1-alpha.62
26832683
"@storybook/addon-actions": ^6.5.10
26842684
"@storybook/addon-docs": ^6.5.10

0 commit comments

Comments
 (0)