Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering to string results in empty span #44

Open
cfranc0 opened this issue Feb 2, 2021 · 1 comment
Open

Rendering to string results in empty span #44

cfranc0 opened this issue Feb 2, 2021 · 1 comment

Comments

@cfranc0
Copy link

cfranc0 commented Feb 2, 2021

Describe the bug
When trying to user the renderToString function available in react-dom/server, the resulting HTML output does not contain the equation.

To Reproduce

import React from 'react';
import { renderToString } from 'react-dom/server';

import BlockMath from '@matejmazur/react-katex';

// KaTeX support
import 'katex/dist/katex.min.css'

function TeXter() {
  const tex = renderToString(<BlockMath math="f(x)=\lim_{x\to\infin}\int_a^b e^x" />);

  return (
    <div className="content" dangerouslySetInnerHTML={{__html: tex}}>

    </div>
  );
}
//...

Expected behavior
To return the complete HTML rendering of a given TeX equation.

Screenshots
This is the resulting HTML
immagine

  • OS: Windows 10 Pro, 1909
  • Browser: Firefox
  • Version: 85.0

Additional context
The react-katex package appears to be working just fine in this context

immagine

To get to this stage I just changed the import line to import {BlockMath} from 'react-katex';

@MatejBransky
Copy link
Owner

MatejBransky commented Apr 15, 2021

This is caused by empty inital state. I'm thinking how to render HTML once on client side because if I render math immediately in useState then I immediately replace this value with the same one in useEffect.

This looks related: https://medium.com/swlh/how-to-use-useeffect-on-server-side-654932c51b13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants