1

I don't know why my editor loses focus while I type each time. Steps to reproduce

  1. type something in ReactQuill (atm it's normal),
  2. navigate to page b
  3. will detect url change, and pop up Prompt to let the user setState in Parent component.
  4. now in page b, we switch back to page a
  5. this time, every time I type in editor, the editor lose focus, and shows warning in console

addRange(): The given range isn't in document.

PS: If I put the ReactQuill outside the Routes, it works without any losing focus issue. react version 16, react-quill 1.3.5

class Parent extends React.Component {
 ...
render() {
<Routes>
  <Route element={<Layout />} >
    <Route path="/a" element={(
       <PromptWrapper>
         <ReactQuill
            style={{ marginBottom: 15 }}
            minHeight={100}
            innerRef={(ref) => this.aboutUsEditor = ref}
            theme="core"
            value={aboutUsDescription}
            onChange={(text, delta, source) =>
              this.handleChangeEditor(text, delta, source,)
            }
            modules={{
              toolbar: false,
            }}
          />
       </PromptWrapper>
    )}/>
    <Route path="/b" element={(
       <div>
         Page 2
       </div>
    )}/>
  </Routes>

Is there anything I should be aware ? Thanks

KHman
  • 31
  • 1
  • 5
  • Would it be possible to create a *running* [codesandbox](https://codesandbox.io/) demo that reproduces this issue that we could inspect and debug live? – Drew Reese Aug 17 '22 at 04:41
  • Hi Drew, my project is complicated, actually even the ReactQuill is another component wrapped in reactQuill. So I just want somebody to tell me the clues or ideas, thanks. – KHman Aug 17 '22 at 04:44
  • Ah, well without a [mcve] it'll likely be difficult for anyone to say why navigating away and back to `"/a"` causes the `ReactQuill` component to behave oddly. I do see this [post](/questions/63597028/react-quill-addrange-the-given-range-isnt-in-document?rq=1) over in the related section. – Drew Reese Aug 17 '22 at 04:52

0 Answers0