Open akoskovacs opened 3 years ago
Thank you for the bug report 😊. I will investigate this issue and try to get back to you as soon as I can.
@akoskovacs
This is how I handle it
// @ts-ignore
let ReactTrixRTEInput;
let ReactTrixRTEToolbar;
function RichTextEditorComponent() {
const [isServer, setIsServer] = useState(true);
useEffect(() => {
try {
if (window) {
ReactTrixRTEInput = require('react-trix-rte').ReactTrixRTEInput;
ReactTrixRTEToolbar = require('react-trix-rte').ReactTrixRTEToolbar;
setIsServer(false);
}
} catch (err) {
//
}
}, []);
return (
<div>
{isServer ? null : (
<>
<ReactTrixRTEToolbar toolbarId="react-trix-rte-editor" />
<ReactTrixRTEInput
toolbarId="react-trix-rte-editor"
defaultValue="<div>This works!</div>"
onChange={console.log}
/>
</>
)}
</div>
);
}
export default RichTextEditorComponent;
@akoskovacs Are you still facing this issue? Could you help me reproduce it with a sample codesandbox?
I tried the code from @rash3ye above in a Next.js project, and still see this issue.
It is clearly the server side rendering that is causing the issue, because it checks for window.
Using Next.js also. When refreshing will hit theReferenceError: window is not defined
error.
For Next.js, I am using dynamic import with ssr: false
to overcome this problem:
const TrixEditor = dynamic(() => import("form-controls/TrixEditor"), {
ssr: false,
loading: () => <p>Loading editor...</p>,
});
const NoteExample = () => {
return (
<TrixEditor />
)
}
Hi!
I tried to use
react-trix-rte
in SSR context. Of couse this means nowindow
ordocument
object exist, but the editor tries to access that.This is the error I am getting:
ReactOnRails::PrerenderError in Posts#index
Related gems used:
Code used: