remirror icon indicating copy to clipboard operation
remirror copied to clipboard

window is not defined using NextJs

Open dalladirosa opened this issue 3 years ago • 5 comments

Summary

I got an error ReferenceError: window is not defined

Steps to reproduce

  1. Install remirror recent version
  2. Create a new page
  3. 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>
  1. Open the page

Expected results

Show remirror editor

Actual results

Get an error ReferenceError: window is not defined

Possible Solution

Screenshot(s)

image image

dalladirosa avatar Sep 06 '21 11:09 dalladirosa

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>

SunPj avatar Sep 28 '21 07:09 SunPj

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

dalladirosa avatar Sep 28 '21 12:09 dalladirosa

Yeah getting the same. Curious as the readme says SSR should work perfectly fine.

Powersource avatar Oct 25 '21 18:10 Powersource

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;

edwinvelez avatar Feb 03 '22 20:02 edwinvelez

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

Kaempy avatar Dec 11 '22 18:12 Kaempy