arnog / react-mathlive

Example using the React bindings for Mathlive
19 stars 17 forks source link

Server Side Rendering #8

Closed ramon-adan closed 10 months ago

ramon-adan commented 2 years ago

Is there a way to support MathLive on SSR?, I get this error;

ReferenceError: document is not defined at /node_modules/mathlive/dist/mathlive.min.js:2:912106 at /node_modules/mathlive/dist/mathlive.min.js:2:69 at Object. (/node_modules/mathlive/dist/mathlive.min.js:2:209)

I'm using the latest version of Mathlive 0.72.1

hobo1618 commented 1 year ago

Hey I ran into the same issue. Are you using NextJS? If so you can fix the issue by creating a component and then importing that component dynamically. The MathView component therefore won't be rendered on the server (it's a web component under the hood which extends HTMLElement), but the rest of your app can be. Basically this workaround lazyloads the web component. Here's an example repo that demonstrates the idea.

Mopiel commented 10 months ago

We have the same problem on 0.77.0 :(

arnog commented 10 months ago

The current version of MathLive is 0.95.5.

Mopiel commented 10 months ago

@arnog It works with 0.95.5. We just need to change our current logic to adjust to the latest version. Thank you 👍