fast-reflexes / better-react-mathjax

MIT License
124 stars 16 forks source link

f.createElement is not a functin #63

Closed rabbit16 closed 3 months ago

rabbit16 commented 3 months ago

When I import MathJaxContext to display math content and compile it using the command yarn build, an error stating 'f.createElement is not a function' appears on my page. However, the development environment works fine, and the error only occurs after building. I couldn't figure it out. What should I do? image This is content component


    const value = content || ''
    if (position === 'right') {
      return (
        <div ref={markdownBodyRef} className="markdown-body">
          <TeX math={value} />
        </div>
      )
    }
    const renderMdHtml = mdi.render(value)
    return (
      <div
        ref={markdownBodyRef}
        className="markdown-body"
        dangerouslySetInnerHTML={{
          __html: renderMdHtml
        }}
      />
    )
  }, [content, position]) 

{status === 'loading' ? <OpenAiLogo rotate /> : <MathJaxContext config={config}>
            <MathJax hideUntilTypeset={"first"}>
              {renderText}
              </MathJax>
              </MathJaxContext>}
rabbit16 commented 3 months ago

I used react frame.

fast-reflexes commented 3 months ago

To begin with, you should never return the MathJaxContext conditionally like that and also in the middle of a component that it mounted and unmounted between renderings. Follow the instructions in the README : https://github.com/fast-reflexes/better-react-mathjax?tab=readme-ov-file#usage

If the problem persists, I can take another look.

fast-reflexes commented 3 months ago

Closing this since no new input has been received, feel free to reopen if more info can be provided.

rabbit16 commented 3 months ago

I've already resolved the issue by downgrading the version of Vite. The original version of Vite was 3.0, and after downgrading to version 2.0 and recompiling, everything worked fine.

fast-reflexes commented 3 months ago

I can confirm that it works perfectly with Vite 5 both in development and in production. Haven't tried with Vite 3.