Skip to content

Commit 198c437

Browse files
Merge pull request #912 from GetStream/vishal/gallery-memoization
fix: avoid unnecessary gallery image re-rendering upon message update
2 parents 56a47d4 + 77f2237 commit 198c437

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

package/src/components/Attachment/Gallery.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
useOverlayContext,
2727
} from '../../contexts/overlayContext/OverlayContext';
2828
import { useTheme } from '../../contexts/themeContext/ThemeContext';
29-
import { makeImageCompatibleUrl } from '../../utils/utils';
29+
import { getUrlWithoutParams, makeImageCompatibleUrl } from '../../utils/utils';
3030

3131
import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
3232
import type {
@@ -393,8 +393,8 @@ const areEqual = <
393393
prevImages.length === nextImages.length &&
394394
prevImages.every(
395395
(image, index) =>
396-
image.image_url === nextImages[index].image_url &&
397-
image.thumb_url === nextImages[index].thumb_url,
396+
getUrlWithoutParams(image.image_url) === getUrlWithoutParams(nextImages[index].image_url) &&
397+
getUrlWithoutParams(image.thumb_url) === getUrlWithoutParams(nextImages[index].thumb_url),
398398
);
399399
if (!imagesEqual) return false;
400400

package/src/utils/__tests__/utils.test.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/src/utils/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,15 @@ export const ACITriggerSettings = <
535535
export const makeImageCompatibleUrl = (url: string) =>
536536
(url.indexOf('//') === 0 ? `https:${url}` : url).trim();
537537

538+
export const getUrlWithoutParams = (url?: string) => {
539+
if (!url) return url;
540+
541+
const indexOfQuestion = url.indexOf('?');
542+
if (indexOfQuestion === -1) return url;
543+
544+
return url.substring(0, url.indexOf('?'));
545+
};
546+
538547
export const vw = (percentageWidth: number, rounded = false) => {
539548
const value = Dimensions.get('window').width * (percentageWidth / 100);
540549
return rounded ? Math.round(value) : value;

0 commit comments

Comments
 (0)