BUG: ZoneWidget.getHorizontalSashTop() compares style.height to null, returns NaN before height is set
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version:
mainat commit 1d20abca144f85864e4f9a467f29e7b0bcd86489 (package version 1.148.0) - OS Version: Ubuntu 24.04.5 LTS, Node v22.23.5 (platform-independent DOM logic)
Description
In src/vs/editor/contrib/zoneWidget/browser/zoneWidget.ts (line 577), getHorizontalSashTop() compares style.height to null:
getHorizontalSashTop() {
return (this.domNode.style.height === null ? 0 : parseInt(this.domNode.style.height)) - (this._decoratingElementsHeight() / 2);
}
CSSStyleDeclaration.height returns an empty string "" when no inline height is set. It never returns null, so the === null branch is dead code. With no height set, parseInt("") is NaN, and the method returns NaN.
The inline height is only assigned later, in _onViewZoneHeight (line 293), after the view zone is added in _showImpl. Until that callback runs, getHorizontalSashTop() returns NaN. This is the only style.* === null comparison under src/.
Steps to Reproduce
npm install jsdom- Run this script. It uses the exact expression from line 577 on a bare
div, like the oneZoneWidgetcreates:
const { JSDOM } = require('jsdom');
const { document } = new JSDOM('<!doctype html><body></body>').window;
const domNode = document.createElement('div');
const decoratingElementsHeight = 14; // example value
const getHorizontalSashTop = () =>
(domNode.style.height === null ? 0 : parseInt(domNode.style.height)) - (decoratingElementsHeight / 2);
console.log(JSON.stringify(domNode.style.height)); // ""
console.log(domNode.style.height === null); // false
console.log(getHorizontalSashTop()); // NaN
domNode.style.height = '120px';
console.log(getHorizontalSashTop()); // 113
Actual: "", false, NaN, then 113 once the height is set.
Expected: The first call returns -7 (0 - decoratingElementsHeight / 2), as the dead === null ? 0 branch intended.
Suggested fix
getHorizontalSashTop() {
const height = parseInt(this.domNode.style.height);
return (isNaN(height) ? 0 : height) - (this._decoratingElementsHeight() / 2);
}
With this change, the script above returns -7 before the height is set.
Notes
- Found by code inspection. I verified the DOM behavior with jsdom, but I have not observed a user-visible symptom in a built VS Code.
- Severity is likely low, since the height is assigned shortly after
show().