microsoft / microsoft/monaco-editor

[Bug] Monaco Editor prevents <td> from shrinking in table-layout: auto (Standard Table Layout)

Open
#5,202 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

example

Monaco Editor Playground Code
const value = /* set from `myEditor.getModel()`: */ `function hello() {
	alert('Hello world!');
}`;

// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
	value,
	language: "javascript",
	automaticLayout: true,
});

const btn = document.getElementById('myButton');
  btn.onclick = function() {
	document.querySelector('#container').className = 'fullscreen'
};

const btn2 = document.getElementById('myButton2');
  btn2.onclick = function() {
	document.querySelector('#container').className = ''
};



<table style="width: 100%">
    <tr>
        <td>
            <div>123234234</div>
        </td>
        <td>
            <div id="container" style="height: 100px"></div>
        </td>
    </tr>
</table>
<div style="margin-top: 100px">
<button id="myButton">fullscreen</button>
<button id="myButton2">undo</button>
</div>



.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100px;
    z-index: 9999;
    min-height: unset;
  }
Reproduction Steps
  1. Go to the Monaco Editor Playground.

  2. Wrap the editor container in a standard HTML table with table-layout: auto.

<table style="width: 100%; border: 1px solid red;">
  <tr>
    <td style="width: 200px;">Sidebar Content</td>
    <td>
      <div id="container" style="height: 400px; border: 1px solid blue;"></div>
    </td>
  </tr>
</table>
  1. Initialize the editor with automaticLayout: true.

  2. Try to resize the browser window to a narrower width.

  3. Notice that as the window shrinks, the containing the editor stops shrinking once it reaches the initial width of the editor, eventually causing the table to overflow its parent container or the window.

Actual (Problematic) Behavior

In a table-layout: auto (default) environment, the is constrained by its "min-content" width. Since Monaco Editor renders its internal components (like the view-lines and scrollable layers) with absolute pixel widths, the browser treats these as non-shrinkable content.

Consequently, the refuses to become narrower than the editor's current width. Because the doesn't shrink, automaticLayout is never triggered to recalculate a smaller width, creating a deadlock where the table remains wide and breaks the responsive layout.

Expected Behavior

The should be able to shrink according to the table's flexible layout rules, even if its content (Monaco Editor) is currently wider. Once the width decreases, automaticLayout should detect the container's new size and re-render the editor with a matching smaller width.

Essentially, the internal canvas/DOM of the editor should not act as a "hard" minimum width constraint for a table cell.

Additional Context

The issue is specific to table-layout: auto. While switching to table-layout: fixed solves the shrinking problem, it is not a viable solution for many users because:

  1. fixed layout ignores the natural width of other dynamic columns.

  2. It forces a rigid structure that doesn't fit data-heavy applications where columns should adapt to their headers/content.

A potential workaround is to use position: absolute on the editor container to take it out of the document flow, but this requires a fixed height and extra wrapper divs, which is not an ideal developer experience.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Monaco Editor Playground reproduction and the automaticLayout configuration, then inspect how the editor responds when its table cell narrows under table-layout: auto. Reproduce the overflow, trace the relevant layout behavior, and verify that the cell can shrink and the editor recalculates to the smaller container width.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.