Skip to content

Commit

Permalink
Prevent flash of reload due to invalidation happening when we dont ha…
Browse files Browse the repository at this point in the history
…ve a revalidation required in this case

Signed-off-by: MTRNord <[email protected]>
  • Loading branch information
MTRNord committed Nov 18, 2024
1 parent 2f5c62d commit 90c9e55
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { WidgetApi } from '@matrix-widget-toolkit/api';
import { useWidgetApi } from '@matrix-widget-toolkit/react';
import { styled } from '@mui/material';
import { IDownloadFileActionFromWidgetResponseData } from 'matrix-widget-api';
import React, { useCallback } from 'react';
import useSWR from 'swr';
import { useCallback } from 'react';
import useSWRImmutable from 'swr/immutable';
import { convertMxcToHttpUrl, WidgetApiActionError } from '../../../lib';
import { ImageElement } from '../../../state';
import {
Expand Down Expand Up @@ -157,12 +157,14 @@ function ImageDisplay({
overrides = {},
}: ImageDisplayProps) {
const widgetApi = useWidgetApi();
const { data: imageUri } = useSWR(
const { data: imageUri } = useSWRImmutable(
{ widgetApi, baseUrl, mxc, mimeType },
downloadFile,
{ suspense: true },
);

console.log('render');

const handleLoad = useCallback(() => {
// This can happen directly when the image is loaded and saves some memory.
if (imageUri) {
Expand Down Expand Up @@ -205,4 +207,4 @@ function ImageDisplay({
);
}

export default React.memo(ImageDisplay);
export default ImageDisplay;

0 comments on commit 90c9e55

Please sign in to comment.