Skip to content
\n

I see two ways to fix this:

\n
    \n
  1. Somehow get the fix in the styled-jsx package
  2. \n
  3. Figure out why there are empty style attributes in the SVG/HTML generated by rehype-typst, and change this somehow.
  4. \n
\n

Issue 2

\n

React does not support namespaces in the svg string generated by typst:

\n
SyntaxError: Namespace tags are not supported by default. React's JSX doesn't support namespace tags. You can set `throwIfNamespace: false` to bypass this warning.\n
\n

We can work around this by ignoring the react error in the .babelrc file, with the following config:

\n
{\n  \"presets\": [\n    [\n      \"next/babel\",\n      {\n        \"preset-react\": { \"throwIfNamespace\": false }\n      }\n    ]\n  ],\n  \"plugins\": []\n}
\n

Perhaps one way to work around this is to add an option in rehype-typst to convert the resulting SVG files into JSX format.
\nThis could be off by default, but would have to be turned on for React apps.

\n

I did some quick searching, but could not find an npm plugin to automatically convert SVG to JSX, but I found this online app, which is open source. So we could take a look and see how they do it, perhaps publish it as an npm package.

\n

Let me know what you think!

\n

I'll try to do the following at some point in the future:

\n
    \n
  1. create a minimal repo for Nextjs + rehype-typst + MDX for testing (which I will share here if/when it's done)
  2. \n
  3. comment on the pull request in the styled-jsx package.
  4. \n
","upvoteCount":2,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"

Thanks for the responses!

\n

I just tried out the latest Next.js version, including the app router.
\nIt works fine!
\n(With the exception of a hydration error, but that's not a big problem.)

\n

You can check out here: https://github.com/Loosetooth/next-rehype-typst-mdx

\n

As such you can ignore my opening comment above. I tried that out in an older project.
\nSeemingly, those issues have already been fixed one way or another.

","upvoteCount":3,"url":"https://github.com/Myriad-Dreamin/typst.ts/discussions/517#discussioncomment-9193594"}}}

rehype-typst + Next.js + MDX #517

Answered by Loosetooth
Loosetooth asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the responses!

I just tried out the latest Next.js version, including the app router.
It works fine!
(With the exception of a hydration error, but that's not a big problem.)

You can check out here: https://github.com/Loosetooth/next-rehype-typst-mdx

As such you can ignore my opening comment above. I tried that out in an older project.
Seemingly, those issues have already been fixed one way or another.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Loosetooth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants