From c0f7c5960f21fba94b4810e0be0a3a526793f53e Mon Sep 17 00:00:00 2001 From: Joe Anderson Date: Fri, 22 Dec 2023 16:21:42 +0000 Subject: [PATCH] Fix: Plate ignores plugins passed via `editor` --- .changeset/chilled-ligers-jam.md | 3 ++- packages/core/src/components/Plate.spec.tsx | 22 +++++++++++++++++++++ packages/core/src/hooks/usePlateEffects.ts | 3 ++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.changeset/chilled-ligers-jam.md b/.changeset/chilled-ligers-jam.md index 84c381ffcc..e0a35cf229 100644 --- a/.changeset/chilled-ligers-jam.md +++ b/.changeset/chilled-ligers-jam.md @@ -2,4 +2,5 @@ '@udecode/plate-core': patch --- -Fix: `readOnly` on Plate store defaults to false and overrides `readOnly` on PlateContent +- Fix: `readOnly` on Plate store defaults to false and overrides `readOnly` on PlateContent +- Fix: Plate ignores plugins passed via `editor` diff --git a/packages/core/src/components/Plate.spec.tsx b/packages/core/src/components/Plate.spec.tsx index a1a7b058ee..cde740713b 100644 --- a/packages/core/src/components/Plate.spec.tsx +++ b/packages/core/src/components/Plate.spec.tsx @@ -132,6 +132,28 @@ describe('Plate', () => { expect(result.current.at(-1)!.key).toBe('test2'); }); }); + + it('should use plugins from editor', () => { + const _plugins = [{ key: 'test' }]; + const editor = createPlateEditor({ plugins: _plugins }); + + const wrapper = ({ children }: any) => ( + {children} + ); + + const { result, rerender } = renderHook( + () => usePlateSelectors().plugins(), + { + wrapper, + } + ); + + expect(result.current.some((p: any) => p.key === 'test')).toBe(true); + + rerender(); + + expect(result.current.some((p: any) => p.key === 'test')).toBe(true); + }); }); describe('when id updates', () => { diff --git a/packages/core/src/hooks/usePlateEffects.ts b/packages/core/src/hooks/usePlateEffects.ts index 36506dd36e..6b67a1fe95 100644 --- a/packages/core/src/hooks/usePlateEffects.ts +++ b/packages/core/src/hooks/usePlateEffects.ts @@ -1,5 +1,6 @@ import { useEffect } from 'react'; import { Value } from '@udecode/slate'; +import { isDefined } from '@udecode/utils'; import { PlateProps } from '../components'; import { useEditorRef, usePlateStates } from '../stores'; @@ -26,7 +27,7 @@ export const usePlateEffects = < const [, setPlugins] = states.plugins(); useEffect(() => { - if (pluginsProp !== rawPlugins) { + if (isDefined(pluginsProp) && pluginsProp !== rawPlugins) { setRawPlugins(rawPlugins); setPlatePlugins(editor, {