GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • Archive
  • Photos
  • About
  • Contact
  • Search

This view

  • Original page
  • New address

GeezerVison is showing www.peterbe.com — From @monaco-editor/react to prism-react-editor - Peterbe.com

From @monaco-editor/react to prism-react-editor

Thursday, Sep 25, 2025
0 comments Web development, React, JavaScript

I needed a in-browser editor for editing SQL. Initially, I used used @monaco-editor/react which sits on top of monaco-editor and it's a beast.

The problem was that monaco is very large. And I don't know why, but it dynamically loads other files from a CDN, as demonstrated by this Network panel for JS files:

Network Before

I needed something more lightweight and found prism-react-editor which looks very promising.

Now, the network chart looks like this:

Network after

When I make PRs against this project, I have a GitHub Action that posts a comment about the change in size of the total static asset bundle. It looked like this:

Total bundle size comment

Yay! More than 4MB smaller. Admittedly, it's comparing apples to pineapples but good to know.

Keyboard shortcut

One important feature that took me some figuring out was how to make Cmd-Enter trigger a form submission.

This is/was how you do it with @monaco-editor/react:


import type { editor } from "monaco-editor"
import { KeyCode, KeyMod } from "monaco-editor"
// ...

const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null)
const monacoEditor = editorRef.current
const editorRef = useRef<PrismEditor | null>(null)

if (monacoEditor) {
  monacoEditor.addCommand(KeyCode.Enter | KeyMod.CtrlCmd, () => {
    // Your code to execute when Ctrl/Cmd + Enter is pressed
  }
}

And this is how you accomplish the same with prism-react-editor:


import { type PrismEditor } from "prism-react-editor"

// ...

const editorRef = useRef<PrismEditor | null>(null)

useEffect(() => {
  const editor = editorRef.current
  if (editor) {
    const oldEnterCallback = editor.keyCommandMap.Enter
    editor.keyCommandMap.Enter = (e, selection, value) => {
      if (e.metaKey) {
        // Your code to execute when Ctrl/Cmd + Enter is pressed
        return true
      }
      return oldEnterCallback?.(e, selection, value)
    }
  }
})

Theming

I didn't use AI to make this migration, but I do admit that since it is a side-project I didn't send a whole lot of time reading the manual. After a bit of hacking I figured out how I can get the editor correctly themed in my Mantine app:


import "prism-react-editor/themes/vs-code-light.css" // default

function injectStylesheet(cssText: string): void {
  const existing = document.getElementById("prism-theme")
  if (existing) {
    existing.textContent = cssText
  } else {
    const style = document.createElement("style")
    style.id = "prism-theme"
    style.textContent = cssText
    document.head.appendChild(style)
  }
}

export function Component() {
  const { colorScheme } = useMantineColorScheme()

  useEffect(() => {
    loadTheme(colorScheme === "light" ? "vs-code-light" : "vs-code-dark").then(
      (theme) => {
        if (theme) injectStylesheet(theme)
      },
    )
  }, [colorScheme])

  // ...

That seems to work.

Your email will never ever be published.

Related posts

Previous:
How I end-to-end test my Bun CLI app September 18, 2025 Bun
Next:
Find the source of an alias in bash September 29, 2025 Linux, Bash, macOS
Related by category:
Testing out vite 8 on SPA: Vite 8 is 5x faster December 6, 2025 Web development
describetime - A command line tool to say a date-time in different ways October 22, 2026 JavaScript
useSlowTruth - React hook to throttle booleans August 10, 2026 React
gg2 branches got 50% faster by a Promise.all February 16, 2026 JavaScript
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.