CharlieMcVicker / mathjax-react

React Component Library for MathJax
33 stars 14 forks source link

Doesn't work with server-side rendering #11

Open ashemag opened 3 years ago

ashemag commented 3 years ago

Error

ReferenceError: window is not defined

for server-sider rendering (like when using next.js)

alfonso1003 commented 3 years ago

@ashemag , I'm using Next.js and encountering this issue for the first time also. In my specific app, if I navigate directly to the page with a MathComponent element, then I get the same ReferenceError you have. If I go through my app's entire process flow to get to the page, then the MathComponent renders. But yeah, there's something wrong with how Next.js is handling this.

I haven't found a solution yet, but I'm looking at these two links and I think I'm on the right track with these. I'll report back if I make any progress. https://louisrli.github.io/blog/2020/06/04/react-mathjax/#.X-I4T9hKhPY https://louisrli.github.io/blog/2020/06/04/react-dynamic-script-hook/#.X-I24dhKhPY

CharlieMcVicker commented 3 years ago

This is because we use the browserHTML adpator within Mathjax, which seems to expect window to be defined. It would be a good idea to make this configurable.