Skip to content

Support direct HTML generation mode #2638

@oliviertassinari

Description

@oliviertassinari

Initial checklist

Problem

TL;DR: The way MDX works fundamentally leads to much slower build and runtime compared to a pure Markdown -> HTML generation.

Current solutions

From how I understand MDX, it works like this:

  1. On the build side, it takes Markdown and it converts it to React JavaScript (React.createElement), as described in https://mdxjs.com/packages/mdx/#use.
  2. On the runtime side:
    a. The React.createElement is inlined in the Next.js RSC payload
    b. React takes the RSC payload and hydrates it (yes Next.js needs to hydrate RSC too, but it's not as costly as client components, see NEXTJS 13: self.__next_f.push vercel/next.js#42170).

This is opposition to tools like marked:

  1. On the build side, it takes Markdown and converts it to HTML directly.
  2. On the runtime:
    a. The string representation is inlined in the Next.js RSC payload
    b. React takes the RSC payload and hydrates it with innerHTML (dangerouslySetInnerHTML).

Now, the problem is that each step seems much slower on the MDX side:

Proposed solutions

So I wonder if MDX would be interested in supporting a hybrid rendering mode. For example, allowing a header to be either an HTML string output https://marked.js.org/using_pro#renderer, or a React element. My hope is that this could lead to much faster build time (e.g. no need anymore for Rust https://nextjs.org/docs/app/guides/mdx#using-the-rust-based-mdx-compiler-experimental) and much faster render time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🤞 phase/openPost is being triaged manually

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions