-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Editing Area losing focus in React 16 #309
Comments
I have this issue as well. Tried a lot of things before finding this. Removing Custom Editing Area stopped the error. |
Any news on that problem ? I have it too... I found that the key of the div is updated each time you submit a statechange |
See #309 This _may_ be related to a change in React 16: https://github.com/facebook/react/blob/master/CHANGELOG.md#breaking-changes
This may be due to a change in the lifecycle of React components in React 16. One of these?
|
Try to set an id for parent and child. static getDerivedStateFromProps(props, state) {
if (props.id !== state.id) {
return {
id: props.id,
editorHtml: props.defaultValue,
};
}
return null;
} |
Like this: https://codesandbox.io/s/k3jqjr78pr ? |
+1 Interested to see this fixed |
+1 Same Issue |
Noticed that error occurs only in dev mode, after I build assets with webpack it doesn't reproduce anymore. |
Hey guys, can I work in this issue? |
Yes, please do! @erick2014 |
Is there already a solution for this? Or a viable workaround? I have migrated from React 15 to React 16 this weekend. When I type in my input field, many times (it seems to be working when typing REALLY slow) the cursor jumps back to position 0 (the front). I would prefer not rewriting any Quill implementation code, since it was working smooth as butter on React15 and I am hesitant to rewrite/refactor and introduce bugs in existing production code... Edit: currently working around this issue by not using children components in the QuillEditor ReactQuill component. |
+1 same issue. |
huy guys, I'm checking this issue to see what's the problem |
@alexkrolick is there any contribution guide to follow? I have no idea how to debug this |
You can step through the editor in the example with Chrome devtools |
+2 same issue too |
@alexkrolick do you mean checking the demo in the repo? |
Yes, clone locally and run the demo build in package.json, then you can debug a live editor |
same issue |
Same issue |
same issue |
Are there any known workarounds to this bug? |
I ended up using draft js after a lot of research on this. |
Same issue.... Quill is brought to it's knees when using: "div className="my-editing-area" Warning: isMounted(...) is deprecated in plain JavaScript React classes. Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks. |
My experience with Quill - Problems + solutions: My environemt: imagine a left panel with items from 1 to 10, and the main container with 6 properties to be filled in by User with React Quill text editor, so 60 properties in total. Problem 1: Solution: Problem 2: Solution: and that this content goes to ReactQuill value property, so ..., value={content} ... Problem 3: Solution: Problem 4:
which means, that on every change it gets the content (which is the Delta) and returns it in callback together with textHTML. Solution:
so whenever it starts working on a string data initially, it continues on a string, and when the initial value is Delta, it is working on Delta. Problem 5: Solution:
this Problem 6: Soliution:
This means, that for initial values provided to Quill that are of type string, but have something inside, it will work in the string mode, Hope it will help some of You guys help Your issues. |
@MateuszKrazek Like a lot of other people who are seeing the Thanks! |
I had, again, the same issue and this time, it was caused by changing the value in the handler (removing extra function MyEditor({ value, onChange }){
const [state, setState] = useState({ value });
useEffect(() => {
if (state.value !== value) setState({ value });
}, [value]);
return (
<Editor
value={state.rawValue || state.value || ''}
onChange={rawValue => {
const cleanedValue = rawValue.replace(/<p><br><\/p>/g, '');
setState({ rawValue, value: cleanedValue });
onChange(cleanedValue);
}}
/>
);
} |
In my project with your code, the issue persist mate. |
@renaudtertrais in your example you're not using a custom editing area, try this example and you will see this bug it's still open... function MyEditor({ value, onChange }){
const [state, setState] = useState({ value });
useEffect(() => {
if (state.value !== value) setState({ value });
}, [value]);
return (
<Editor
value={state.rawValue || state.value || ''}
onChange={rawValue => {
const cleanedValue = rawValue.replace(/<p><br><\/p>/g, '');
setState({ rawValue, value: cleanedValue });
onChange(cleanedValue);
}}
>
<div id="target"></div>
</Editor>
);
} |
I had this issue and got it working by using const MyEditor = () => {
const [editorContent, setEditorContent] = React.useState(``)
return (
<ReactQuill
defaultValue={editorState}
onChange={(value) => setEditorState(value)}
/>
)
} |
@robphoenix check out this post #309 (comment) and read the Problem #1. |
@MateuszKrazek ok, sorry you still have issues, this is just what fixed it for me 🤷♀️ |
FWIW I encountered the same issue when I included Quill in a functional component, which was then being rendered as a child of another functional component. The issue seemed to be present when I used a combination of The "solution" (read: workaround) was to use a class component instead for the Quill editor. Below is my new (working) Quill component:
Hope it helps. |
@robphoenix solution worked great. Side note: if one is fetching their defaultValue asynchronously, make sure it's received and set before rendering the quill component — and this works great! |
Hello all! Most of the issues in this thread, with related issues related to state changes and focus management, have been a core topic in the latest beta versions. The update detection and regeneration mechanisms have been reworked, and everything should now work properly when using I have updated the Codepen on the original post to the latest beta, and I don't seem to be getting any ill effects anymore: https://codepen.io/zenojevski/pen/LYpbyVP?editors=0010 Can you verify? Note: white-space issues when using strings are acknowledged, even though there is no solution yet. They might be improved by using the |
@zenoamaro apparently |
Prevent creating modules object each render. |
It's seems that each re-render the modules object are recreating. To prevent this behaviour, i used const modules = React.useMemo(
() => ({
toolbar: { ... }
}),
[<any-value-to-compare-or-none>]
) |
thanks @marinona / @murillo94! Works perfectly now :) |
+1 ,the way of @marinona and @murillo94 works !! Thx, you save my day. |
You must use @murillo94 and/or @timtamimi's solution to work, every function and object has to be memoized as a prop or it will clear the focus - so best to use a class |
i've got similar issue when used react-quill.warning addRange(): The given range isn't in document. i used react functional component with: // two states
// standart form handlers
and a form as a return
okay. now what was the problem?The issue uccurs while handling change value event. BEFORE FIX
AFTER FIX
thx. and hope it helps someone. |
@timtamimi converting to class component did not work |
thanks @marinona and @murillo94 it worked, i made a simple mistake of removing bolded completely const modules = React.useMemo( |
either useMemo neither useEffect worked for me on "react-quill": "^1.3.5", "react": "^16.13.1"
|
@Thyrannoizer are you defining "modules" inside the component's definition? It should be outside and it might be the problem.
Hope it helps! |
I've been having the same problem as @Thyrannoizer , doesn't matter whether i define modules inside an useMemo or outside the component's definition, my custom editing area still loses focus after typying and on the console appears a warning message
|
@MiguelAlvarez129 I think your problem is because you are trying to use the Quill Editor as a controlled component. |
THIS SOLUTION WORKED FOR ME IN REACT FUNCTIONAL COMPONENT AS WELL !! Don't use ReactQuill as a controlled component. That means, remove "value" prop from ReactQuill because you dont need to set the value in ReactQuill explicitly because it handles that on its own. You can keep "onChange" function to get the updated value on every change. Now, just have a variable(not a state variable) and set that variable on every change. Then access that very variable when you want to get the whole content.
Hope this works for you too. !! |
That will work for simple cases but sometimes a controlled component is desirable. Eg if you want to modify the value in another component eg a "clear value" button, or if you want to take in asynchronous updates from the backend. |
When I created a keyboard binding to disable delete key(key code 46) I was also facing issue with focus. I fixed the issue by putting my bindings outside of component. Before: After: keyboard:{ |
Thank mate, that work well |
@alexkrolick why has this issue been closed? I see a couple of workarounds but the bug is still there. |
I have noticed an issue after upgrading to React 16. I have a React Quill component that is being managed by the parent.
This code appears to be working in React 15. However, in React 16, it will lose focus and throw this console error after an onChange event; The given range isn't in document. I believe this is due to the selection not being updated correctly. If you take out the custom editing area, this code will work inside React 16.
I have attached an example in Codepen, in here you can set the dependencies for React 15 vs React 16 to notice the error.
In the meantime, we have removed the custom editing area and wrapped React Quill with a styled component and an '.ql-editor' selector to add a custom style to the editing area.
Thanks for your time!
The text was updated successfully, but these errors were encountered: