Skip to content

Commit dfb6474

Browse files
authored
Merge pull request #4410 from udecode/perf/fallback-store
2 parents 7cf5e59 + b105873 commit dfb6474

File tree

4 files changed

+59
-52
lines changed

4 files changed

+59
-52
lines changed

.changeset/khaki-dancers-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@platejs/core': patch
3+
---
4+
5+
PERF: Do not call `createPlateStore` on every hook call for the purposes of the fallback store

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"is-hotkey": "^0.2.0",
6666
"jotai": "~2.8.4",
6767
"jotai-optics": "0.4.0",
68-
"jotai-x": "2.3.2",
68+
"jotai-x": "2.3.3",
6969
"lodash": "^4.17.21",
7070
"nanoid": "^5.1.5",
7171
"optics-ts": "2.4.1",

packages/core/src/react/stores/plate/createPlateStore.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo } from 'react';
1+
import React from 'react';
22

33
import { atom } from 'jotai';
44
import { useAtomStoreSet, useAtomStoreState, useAtomStoreValue } from 'jotai-x';
@@ -94,6 +94,8 @@ const {
9494
usePlateValue: usePlateLocalValue,
9595
} = createPlateStore();
9696

97+
const { usePlateStore: useFallbackPlateStore } = createPlateStore();
98+
9799
export { plateStore, PlateStoreProvider, usePlateLocalStore };
98100

99101
export const usePlateStore = (id?: string) => {
@@ -122,7 +124,7 @@ export const usePlateStore = (id?: string) => {
122124
* case, return a fallback store until an editor becomes active.
123125
*/
124126
const plateControllerExists = usePlateControllerExists();
125-
const fallbackStore = useMemo(createPlateStore, []).usePlateStore();
127+
const fallbackStore = useFallbackPlateStore();
126128

127129
if (!store) {
128130
if (plateControllerExists) {

0 commit comments

Comments
 (0)