Skip to content

Commit

Permalink
Fix: Plate ignores plugins passed via editor
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan committed Dec 22, 2023
1 parent f8fd55f commit c0f7c59
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .changeset/chilled-ligers-jam.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
22 changes: 22 additions & 0 deletions packages/core/src/components/Plate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<Plate editor={editor}>{children}</Plate>
);

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', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/hooks/usePlateEffects.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -26,7 +27,7 @@ export const usePlateEffects = <
const [, setPlugins] = states.plugins();

useEffect(() => {
if (pluginsProp !== rawPlugins) {
if (isDefined(pluginsProp) && pluginsProp !== rawPlugins) {
setRawPlugins(rawPlugins);

setPlatePlugins<V, E>(editor, {
Expand Down

0 comments on commit c0f7c59

Please sign in to comment.