Skip to content
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

Custom editor.background color not applied in Monaco theme via @monaco-editor/react #700

Open
Gaurav-Narayan-Varma opened this issue Mar 17, 2025 · 10 comments

Comments

@Gaurav-Narayan-Varma
Copy link

Describe the bug
A clear and concise description of what the bug is.
Setting editor.background to red via defineTheme doesn't change the background color of the Monaco editor when using it with the @monaco-editor/react package. The property appears to apply only to the minimap, but the background remains unchanged.

Image

To Reproduce

Steps to reproduce the behavior:

  1. Set up a Monaco editor using @monaco-editor/react, tailwind, and Next.js version 15.2.0
  2. Add a custom theme with editor.background set to red (#FF0000) and set it:
                <Editor
                  key={selectedFile.name}
                  theme="vs-dark"
                  height="100vh"
                  language={selectedFile.codeType}
                  value={selectedFile.content || "// No content available"}
                  beforeMount={(monaco) => {
                    monaco.editor.defineTheme("OneDarkPro", {
                      base: "vs-dark",
                      inherit: true,
                        colors: {
                          "editor.background": "#FF0000",
                          "minimap.background": "#FF0000",
                        },
                        rules: []
                    });
                    monaco.editor.setTheme("OneDarkPro");

                    monaco.languages.typescript.typescriptDefaults.setCompilerOptions(
                      {
                        target: monaco.languages.typescript.ScriptTarget.ESNext,
                        jsx: monaco.languages.typescript.JsxEmit.React,
                        jsxFactory: "createElement",
                      }
                    );
                  }}
                />
  1. Observe the editor background remains dark (default), not red

Expected behavior
The background of the Monaco editor should be red (#FF0000) as defined in the custom theme.

Screenshots

Image

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.6
  • Browser: Chrome 132.0.6834.160
  • "@monaco-editor/react": "^4.7.0"
  • "next": "15.2.0",
  • "postcss": "^8.5.3"

Additional context
N/a

@fsd-niraj
Copy link

I can work on this issue.

@maci-kb24
Copy link

The issue you're experiencing is a known limitation with the @monaco-editor/react package. When you define a theme with editor.background property, it doesn't properly apply to the main editing area, though it does affect the minimap.

@Gaurav-Narayan-Varma
Copy link
Author

The issue you're experiencing is a known limitation with the @monaco-editor/react package. When you define a theme with editor.background property, it doesn't properly apply to the main editing area, though it does affect the minimap.

Is there any work around for this issue?

@trydev0303
Copy link

The issue occurs because the editor.background property in the Monaco editor theme definition is not being applied correctly, likely due to a conflict with the vs-dark base theme or a misconfiguration in the theme setup.

To fix this, ensure the theme is defined and set properly before the editor mounts, and verify that the editor.background property is correctly specified.

Additionally, check for any CSS overrides or external styles that might be interfering with the editor's background color. If the problem persists, try using a different base theme or explicitly setting the background color via inline styles or CSS.

Finally, ensure the Monaco editor and its dependencies are up to date to avoid potential bugs.

@Gaurav-Narayan-Varma
Copy link
Author

verify that the editor.background property is correctly specified

I tried all the themes including 'vs', 'hc-black', and 'hc-light', yet the issue still persisted. The theme is defined and set before the editor mounts.

@trydev0303
Copy link

So, the code works fine, but the background of the Monaco editor is red?

@Gaurav-Narayan-Varma
Copy link
Author

So, the code works fine, but the background of the Monaco editor is red?

Just the minimap as you can see in the photo

@trydev0303
Copy link

If only the minimap's background color changes to red while the editor's background remains unchanged, it means the minimap.background property in your custom theme is being applied correctly, but the editor.background property is either being overridden, ignored, or not properly recognized by the Monaco editor.

This suggests a potential issue with how the theme is being applied to the editor itself, possibly due to incorrect configuration, conflicts with the base theme (vs-dark), or external styling interference. Focus on ensuring the editor.background property is correctly defined and applied in the theme setup.

@vanja-veapi
Copy link

Try to Force Background Override in Tailwind or CSS

/* styles/globals.css or a custom CSS file */
.monaco-editor {
  background-color: #ff0000 !important;
}

Instead of relying only on defineTheme, explicitly set the background color via editorOptions:

<Editor
  key={selectedFile.name}
  theme="OneDarkPro"
  height="100vh"
  language={selectedFile.codeType}
  value={selectedFile.content || "// No content available"}
  options={{
    minimap: { enabled: false },
    overviewRulerBorder: false,
    scrollbar: { verticalScrollbarSize: 0 },
  }}
  beforeMount={(monaco) => {
    monaco.editor.defineTheme("OneDarkPro", {
      base: "vs-dark",
      inherit: true,
      colors: {
        "editor.background": "#FF0000",
      },
      rules: [],
    });

    monaco.editor.setTheme("OneDarkPro");
  }}
/>

@Gaurav-Narayan-Varma
Copy link
Author

Try to Force Background Override in Tailwind or CSS

/* styles/globals.css or a custom CSS file */
.monaco-editor {
  background-color: #ff0000 !important;
}

Instead of relying only on defineTheme, explicitly set the background color via editorOptions:

<Editor
  key={selectedFile.name}
  theme="OneDarkPro"
  height="100vh"
  language={selectedFile.codeType}
  value={selectedFile.content || "// No content available"}
  options={{
    minimap: { enabled: false },
    overviewRulerBorder: false,
    scrollbar: { verticalScrollbarSize: 0 },
  }}
  beforeMount={(monaco) => {
    monaco.editor.defineTheme("OneDarkPro", {
      base: "vs-dark",
      inherit: true,
      colors: {
        "editor.background": "#FF0000",
      },
      rules: [],
    });

    monaco.editor.setTheme("OneDarkPro");
  }}
/>

Thanks for the guidance, Vanja — that worked!

However, after applying the One Dark Pro theme, the semantic highlighting seems off. Currently, it looks like this:

Image

Whereas it should look more like this:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants