react-quill: Server side rendering broken since Sep 20th commits
/node_modules/quill/dist/quill.js:2245
var elem = document.createElement('div');
ReferenceError: document is not defined
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 12
- Comments: 22 (1 by maintainers)
This is the cleanest method I have found to import modules that use window or document:
I was able to work around this limitation by instantiating
react-quill
only on the client. Note thatimport
only works on the top level, so I userequire
.I imagine the maintainers of this module should be able to prevent calls to the DOM when it’s not available, without too much trouble. Big +1 for that change.
Here’s my wrapper component to support isomorphic rendering:
I wrote this with dynamic module
this is how to check if it run in a browser or not (i changed a code from @calvintennant ):
This is what i did works fine with SSR on next js
This is the best solution! @samlogan Thanks!!
@Kamez you can try this solution. This worked for my application.
In my eventform I had a field like this:
The component renderQuill has the following setup:
renderQuill.js
As you notice I import a second component ‘./renderQuillReact’ that contains the resize module.
renderQuillReact.js component
Hope this solution works for you!
Following solution works like a charm:
You are right. But It is not working like textarea. How can ı pass form data via this editor.
this solution makes the situation what is re-rendering when onChange event performed
Same (nuxt3, SSR)… using ES modules, cant use require, and dynamic import() seems to be behaving strangely with a condition…
Just curious, why cant quill just do nothing if its not running in the client?
All of my components are bundled up with WebPack and sent from the server using
renderToString
. When quill is included in the server side bundle viaimport
my server crashes with the folowing output:My hack as above using
require
was to work around this crash.