remirror
remirror copied to clipboard
window is not defined using NextJs
Summary
I got an error ReferenceError: window is not defined
Steps to reproduce
- Install remirror recent version
- Create a new page
- Place this code
const { manager, state } = useRemirror({
// extensions,
content: content,
stringHandler: 'html',
});
<AllStyledComponent>
<ThemeProvider className="shadow-none remirror">
<RemirrorSSR
manager={manager}
state={state}
editable={false}
attributes={{
class: 'ProseMirror remirror-editor remirror-a11y-dark',
}}
/>
</ThemeProvider>
</AllStyledComponent>
- Open the page
Expected results
Show remirror editor
Actual results
Get an error ReferenceError: window is not defined
Possible Solution
Screenshot(s)
I bumped into the same issue. One possible quick fix is to disable server side rendering for the editor.
Wrap your component to
import {NoSsr} from "@material-ui/core";
.....
<NoSsr>
<YourComponent />
</NoSsr>
I bumped into the same issue. One possible quick fix is to disable server side rendering for the editor.
Wrap your component to
import {NoSsr} from "@material-ui/core"; ..... <NoSsr> <YourComponent /> </NoSsr>
Thanks for the solution i will try it later
Yeah getting the same. Curious as the readme says SSR should work perfectly fine.
Hopefully you figured this out by now. If not, take a look at Next.js Dynamic Import. Below is an example that loads a React Component from within a page.
import type { NextPage } from 'next';
import dynamic from 'next/dynamic';
const TextEditor = dynamic( () => import('../components/text-editor'), { ssr: false } );
const Home: NextPage = () => {
return (
<>
Next.js Home Page
<TextEditor />
</>
);
};
export default Home;
Hopefully you figured this out by now. If not, take a look at Next.js Dynamic Import. Below is an example that loads a React Component from within a page.
import type { NextPage } from 'next'; import dynamic from 'next/dynamic'; const TextEditor = dynamic( () => import('../components/text-editor'), { ssr: false } ); const Home: NextPage = () => { return ( <> Next.js Home Page <TextEditor /> </> ); }; export default Home;
Thanks @edwinvelez this helped