fix(core): should not refetch avatar when url does not change (#5070)
blob resources are in fact immutable. We do not need to refetch it by swr policies (mount/visibilitychange/etc)
This commit is contained in:
@@ -2,7 +2,7 @@ import { assertExists } from '@blocksuite/global/utils';
|
|||||||
import type { Workspace } from '@blocksuite/store';
|
import type { Workspace } from '@blocksuite/store';
|
||||||
import reduce from 'image-blob-reduce';
|
import reduce from 'image-blob-reduce';
|
||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import useSWR from 'swr';
|
import useSWRImmutable from 'swr/immutable';
|
||||||
|
|
||||||
// validate and reduce image size and return as file
|
// validate and reduce image size and return as file
|
||||||
export const validateAndReduceImage = async (file: File): Promise<File> => {
|
export const validateAndReduceImage = async (file: File): Promise<File> => {
|
||||||
@@ -52,7 +52,7 @@ export function useBlockSuiteWorkspaceAvatarUrl(
|
|||||||
if (url !== blockSuiteWorkspace.meta.avatar) {
|
if (url !== blockSuiteWorkspace.meta.avatar) {
|
||||||
set(blockSuiteWorkspace.meta.avatar);
|
set(blockSuiteWorkspace.meta.avatar);
|
||||||
}
|
}
|
||||||
const { data: avatar, mutate } = useSWR(url, {
|
const { data: avatar, mutate } = useSWRImmutable(url, {
|
||||||
fetcher: async avatar => {
|
fetcher: async avatar => {
|
||||||
assertExists(blockSuiteWorkspace);
|
assertExists(blockSuiteWorkspace);
|
||||||
const blobs = blockSuiteWorkspace.blob;
|
const blobs = blockSuiteWorkspace.blob;
|
||||||
@@ -62,8 +62,7 @@ export function useBlockSuiteWorkspaceAvatarUrl(
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
suspense: true,
|
suspense: false,
|
||||||
fallbackData: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const setAvatar = useCallback(
|
const setAvatar = useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user