-
-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): prevent multiple attached editors
- Loading branch information
Showing
8 changed files
with
93 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@remirror/react': patch | ||
--- | ||
|
||
Prevent multiple editors being attached with a single Provider. This error flags you when you are attaching `getRootProps` to the dom in multiple placeswithin a single editor instance. This can help prevent unwanted behaviour. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...es/@remirror/react/src/components/__tests__/__snapshots__/remirror-provider.spec.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`multiple \`getRootProps\` applied to dom throw an error 1`] = ` | ||
"\`getRootProps\` has been attached to the DOM more than once. It should only be attached to the dom once per editor. | ||
Called 2 times | ||
For more information visit https://remirror.io/docs/errors#rmr0201" | ||
`; |
55 changes: 55 additions & 0 deletions
55
packages/@remirror/react/src/components/__tests__/remirror-provider.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { docNodeBasicJSON } from '@remirror/testing'; | ||
import { createReactManager, render } from '@remirror/testing/react'; | ||
|
||
import { useRemirror } from '../../hooks'; | ||
import { RemirrorProvider } from '../providers'; | ||
|
||
test('`RemirrorProvider`', () => { | ||
const TestComponent: FC = () => { | ||
const { getRootProps } = useRemirror(); | ||
return ( | ||
<div> | ||
<div data-testid='target' {...getRootProps()} /> | ||
</div> | ||
); | ||
}; | ||
|
||
const manager = createReactManager([]); | ||
|
||
const { getByRole, getByTestId } = render( | ||
<RemirrorProvider initialContent={docNodeBasicJSON} manager={manager}> | ||
<TestComponent /> | ||
</RemirrorProvider>, | ||
); | ||
const target = getByTestId('target'); | ||
const editor = getByRole('textbox'); | ||
|
||
expect(target).toContainElement(editor); | ||
}); | ||
|
||
test('multiple `getRootProps` applied to dom throw an error', () => { | ||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
const manager = createReactManager([]); | ||
const TestComponent: FC = () => { | ||
const { getRootProps } = useRemirror(); | ||
|
||
return ( | ||
<div> | ||
<div data-testid='target' {...getRootProps()} /> | ||
<div data-testid='target1' {...getRootProps()} /> | ||
</div> | ||
); | ||
}; | ||
|
||
expect(() => | ||
render( | ||
<RemirrorProvider manager={manager}> | ||
<TestComponent /> | ||
</RemirrorProvider>, | ||
), | ||
).toThrowErrorMatchingSnapshot(); | ||
|
||
spy.mockRestore(); | ||
}); |
31 changes: 3 additions & 28 deletions
31
...c/components/__tests__/providers.spec.tsx → ...ponents/__tests__/theme-provider.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters