hedgedoc / react-client

The frontend of the upcoming version 2.0
https://hedgedoc.dev
GNU Affero General Public License v3.0
104 stars 13 forks source link

Race condition between KaTeX and extraction of first header #1816

Closed mrdrogdrog closed 2 years ago

mrdrogdrog commented 2 years ago

Description If you edit the first headline, that contains latex code, then the rendered latex symbols won't show up in the document title. If you edit another line then the title is rendered correctly.

To Reproduce

  1. Open an empty note.
  2. Don't use frontmatter to trigger the "first-heading-is-title" behaviour.
  3. Insert a headline that contains latex like # $\alpha$ alpha
  4. The document title is now "alpha"
  5. Add another line and edit it
  6. The document title is now "α alpha" bonus:
  7. Edit the headline again.
  8. The document title is now "alpha"

Expected behavior The document title should be correct if editing the headline.

Additional context It seems like the KaTeX rendering is async. The extraction logic is triggered directly after the rendering of the note. So if you edit the headline then the extraction logic might be triggered before the async katex actions has finished. If you edit another line then the headline wasn't modified and the symbol is still present and can be extracted.

mrdrogdrog commented 2 years ago

After the rendering we could place a MutationObserver on the headline to get notified when KaTeX changes the DOM again.

DerMolly commented 2 years ago

This seems to be an extension of https://github.com/hedgedoc/hedgedoc/issues/2899

mrdrogdrog commented 2 years ago

No, actually these are too different problems. This is that react and Katex are running async. The other one is that toc done right filters elements.