mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 14:27:02 +08:00
fix(core): page mode switch sometimes not working (#5306)
Should not pass inline object without memo into `InternalLottie`.
cdc96876b0/packages/frontend/component/src/components/internal-lottie/index.tsx (L77)
In the detail page when during syncing on the cloud, the detail page will be re-rendered constantly because of `useCurrentSyncEngineStatus` hook, which will then cause `PageSwitchItem` to re-render and forcing the internal lottie state to reset. As a result the click event may not be captured somehow.
This commit is contained in:
@@ -45,21 +45,30 @@ const HoverAnimateController = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pageLottieOptions = {
|
||||||
|
loop: false,
|
||||||
|
autoplay: false,
|
||||||
|
animationData: pageHover,
|
||||||
|
rendererSettings: {
|
||||||
|
preserveAspectRatio: 'xMidYMid slice',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const edgelessLottieOptions = {
|
||||||
|
loop: false,
|
||||||
|
autoplay: false,
|
||||||
|
animationData: edgelessHover,
|
||||||
|
rendererSettings: {
|
||||||
|
preserveAspectRatio: 'xMidYMid slice',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const PageSwitchItem = (
|
export const PageSwitchItem = (
|
||||||
props: Omit<HoverAnimateControllerProps, 'children'>
|
props: Omit<HoverAnimateControllerProps, 'children'>
|
||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
<HoverAnimateController {...props}>
|
<HoverAnimateController {...props}>
|
||||||
<InternalLottie
|
<InternalLottie options={pageLottieOptions} />
|
||||||
options={{
|
|
||||||
loop: false,
|
|
||||||
autoplay: false,
|
|
||||||
animationData: pageHover,
|
|
||||||
rendererSettings: {
|
|
||||||
preserveAspectRatio: 'xMidYMid slice',
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</HoverAnimateController>
|
</HoverAnimateController>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -69,16 +78,7 @@ export const EdgelessSwitchItem = (
|
|||||||
) => {
|
) => {
|
||||||
return (
|
return (
|
||||||
<HoverAnimateController {...props}>
|
<HoverAnimateController {...props}>
|
||||||
<InternalLottie
|
<InternalLottie options={edgelessLottieOptions} />
|
||||||
options={{
|
|
||||||
loop: false,
|
|
||||||
autoplay: false,
|
|
||||||
animationData: edgelessHover,
|
|
||||||
rendererSettings: {
|
|
||||||
preserveAspectRatio: 'xMidYMid slice',
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</HoverAnimateController>
|
</HoverAnimateController>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { useWorkspaceStatus } from '@toeverything/hooks/use-workspace-status';
|
|||||||
import { appSettingAtom, currentPageIdAtom } from '@toeverything/infra/atom';
|
import { appSettingAtom, currentPageIdAtom } from '@toeverything/infra/atom';
|
||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import {
|
import {
|
||||||
|
memo,
|
||||||
type ReactElement,
|
type ReactElement,
|
||||||
type ReactNode,
|
type ReactNode,
|
||||||
useCallback,
|
useCallback,
|
||||||
@@ -101,7 +102,7 @@ const DetailPageLayout = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const DetailPageImpl = ({ page }: { page: Page }) => {
|
const DetailPageImpl = memo(function DetailPageImpl({ page }: { page: Page }) {
|
||||||
const currentPageId = page.id;
|
const currentPageId = page.id;
|
||||||
const { openPage, jumpToSubPath } = useNavigateHelper();
|
const { openPage, jumpToSubPath } = useNavigateHelper();
|
||||||
const currentWorkspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
const currentWorkspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
||||||
@@ -200,7 +201,7 @@ const DetailPageImpl = ({ page }: { page: Page }) => {
|
|||||||
<GlobalPageHistoryModal />
|
<GlobalPageHistoryModal />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
const useForceUpdate = () => {
|
const useForceUpdate = () => {
|
||||||
const [, setCount] = useState(0);
|
const [, setCount] = useState(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user