From 910686293cfd30ec67d127ae06df5aae0f1f5692 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 17 Mar 2025 16:57:25 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F(frontend)=20improve=20headin?= =?UTF-8?q?g=20store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reset headings only when the headers are not equal to the previous ones. It will prevent unnecessary rerenders. --- .../features/docs/doc-editor/stores/useHeadingStore.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/stores/useHeadingStore.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/stores/useHeadingStore.tsx index e67800c6..c77ac3cf 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/stores/useHeadingStore.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/stores/useHeadingStore.tsx @@ -1,3 +1,4 @@ +import _ from 'lodash'; import { create } from 'zustand'; import { DocsBlockNoteEditor, HeadingBlock } from '../types'; @@ -24,7 +25,7 @@ export interface UseHeadingStore { resetHeadings: () => void; } -export const useHeadingStore = create((set) => ({ +export const useHeadingStore = create((set, get) => ({ headings: [], setHeadings: (editor) => { const headingBlocks = editor?.document @@ -36,7 +37,9 @@ export const useHeadingStore = create((set) => ({ ), })) as unknown as HeadingBlock[]; - set(() => ({ headings: headingBlocks })); + if (!_.isEqual(get().headings, headingBlocks)) { + set(() => ({ headings: headingBlocks })); + } }, resetHeadings: () => set(() => ({ headings: [] })), }));