Skip to content

Commit 8938eca

Browse files
committed
⚡️(frontend) improve heading store
Reset headings only when the headers are not equal to the previous ones. It will prevent unnecessary rerenders.
1 parent 6867d76 commit 8938eca

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Diff for: src/frontend/apps/impress/src/features/docs/doc-editor/stores/useHeadingStore.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash';
12
import { create } from 'zustand';
23

34
import { DocsBlockNoteEditor, HeadingBlock } from '../types';
@@ -24,7 +25,7 @@ export interface UseHeadingStore {
2425
resetHeadings: () => void;
2526
}
2627

27-
export const useHeadingStore = create<UseHeadingStore>((set) => ({
28+
export const useHeadingStore = create<UseHeadingStore>((set, get) => ({
2829
headings: [],
2930
setHeadings: (editor) => {
3031
const headingBlocks = editor?.document
@@ -36,7 +37,9 @@ export const useHeadingStore = create<UseHeadingStore>((set) => ({
3637
),
3738
})) as unknown as HeadingBlock[];
3839

39-
set(() => ({ headings: headingBlocks }));
40+
if (!_.isEqual(get().headings, headingBlocks)) {
41+
set(() => ({ headings: headingBlocks }));
42+
}
4043
},
4144
resetHeadings: () => set(() => ({ headings: [] })),
4245
}));

0 commit comments

Comments
 (0)