Skip to content

Add example of mdx-editor with Remix V2 in ESM mode #1

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions app/components/editor.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { FC } from "react";
import type { MDXEditorProps } from "@mdxeditor/editor";
import {
MDXEditor,
BlockTypeSelect,
BoldItalicUnderlineToggles,
CodeToggle,
ListsToggle,
Separator,
UndoRedo,
headingsPlugin,
listsPlugin,
markdownShortcutPlugin,
quotePlugin,
thematicBreakPlugin,
toolbarPlugin,
} from "@mdxeditor/editor";

import "@mdxeditor/editor/style.css";

export const Editor: FC<MDXEditorProps> = (props) => {
return (
<MDXEditor
{...props}
plugins={[
headingsPlugin(),
listsPlugin(),
markdownShortcutPlugin(),
quotePlugin(),
thematicBreakPlugin(),
toolbarPlugin({
toolbarContents: () => (
<>
<UndoRedo />
<Separator />
<BoldItalicUnderlineToggles />
<CodeToggle />
<Separator />
<ListsToggle />
<Separator />
<BlockTypeSelect />
</>
),
}),
]}
/>
);
};
13 changes: 9 additions & 4 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

import { PassThrough } from "node:stream";

import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { Response } from "@remix-run/node";
import {
createReadableStreamFromReadable,
type AppLoadContext,
type EntryContext,
} from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server";
Expand Down Expand Up @@ -54,11 +57,12 @@ function handleBotRequest(
onAllReady() {
shellRendered = true;
const body = new PassThrough();
const stream = createReadableStreamFromReadable(body);

responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
new Response(stream, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down Expand Up @@ -103,11 +107,12 @@ function handleBrowserRequest(
onShellReady() {
shellRendered = true;
const body = new PassThrough();
const stream = createReadableStreamFromReadable(body);

responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
new Response(stream, {
headers: responseHeaders,
status: responseStatusCode,
})
Expand Down
17 changes: 7 additions & 10 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import React from "react";
import type { V2_MetaFunction } from "@remix-run/node";
import type { MetaFunction } from "@remix-run/node";
import { ClientOnly } from "remix-utils/client-only";
import { Editor } from "../components/editor.client";

import '@mdxeditor/editor/style.css';

export const meta: V2_MetaFunction = () => {
export const meta: MetaFunction = () => {
return [
{ title: "New Remix App" },
{ name: "description", content: "Welcome to Remix!" },
];
};

const LazyMDXEditor = React.lazy(() => import("@mdxeditor/editor").then(mod => ({default:mod.MDXEditor})));

export default function Index() {
return (
<React.Suspense fallback={<div>Loading...</div>}>
<LazyMDXEditor markdown="Hello world" />
</React.Suspense>
<ClientOnly fallback={<div>Loading...</div>}>
{() => <Editor markdown="Hello world" />}
</ClientOnly>
);
}
Loading