josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
818 stars 108 forks source link

I got ReferenceError: document is not defined in nextjs project. #288

Closed aholeye closed 12 months ago

aholeye commented 1 year ago
image

But, the page is displaying correctly.

josdejong commented 1 year ago

See docs about nextjs: https://github.com/josdejong/svelte-jsoneditor/blob/main/README-VANILLA.md#import-and-use-the-react-component

aholeye commented 1 year ago

It works! Thank you.

aholeye commented 1 year ago

I'm sorry, there is still an issue. When I copy the demo according to the documentation, it works fine. However, when I add a prop mode={Mode.text}, the issue still persists. like this:

        <JSONEditorReact
          content={jsonContent}
          onChange={handler}
          mode={Mode.text}
        />
aholeye commented 1 year ago

After some testing, I have noticed an even stranger phenomenon. Even declaring useState(Mode.tree) within the page causes the same issue. like this:

  const [mode, setMode] = useState(Mode.tree)

even if I haven't used that variable.

josdejong commented 1 year ago

I guess importing Mode to use Mode.tree pulls in the whole library, which gives an issue when rendering server side. You can use the string 'text' instead if that makes life easier. Otherwise, you'll have to import Mode with a dynamic import too.