microsoft / microsoft/monaco-editor
[Bug] Links in hover tooltips show wrong link target on account of empty href attribute
Open
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?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Monaco Editor Playground Code
monaco.languages.register({ id: "mySpecialLanguage" });
monaco.languages.registerHoverProvider("mySpecialLanguage", {
provideHover: function (model, position) {
return xhr("./playground.html").then(function (res) {
return {
range: new monaco.Range(
1,
1,
model.getLineCount(),
model.getLineMaxColumn(model.getLineCount())
),
contents: [
{ value: "[link](https://google.com)" },
// ^ only change from the default hover example
],
};
});
},
});
monaco.editor.create(document.getElementById("container"), {
value: "\n\nHover over this text",
language: "mySpecialLanguage",
});
function xhr(url) {
var req = null;
return new Promise(function (c, e) {
req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (req._canceled) {
return;
}
if (req.readyState === 4) {
if (
(req.status >= 200 && req.status < 300) ||
req.status === 1223
) {
c(req);
} else {
e(req);
}
req.onreadystatechange = function () {};
}
};
req.open("GET", url, true);
req.responseType = "";
req.send(null);
}).catch(function () {
req._canceled = true;
req.abort();
});
}
Reproduction Steps
- Hover over any of the text in the preview section
- Hover over the "link" text in the opened tooltip
Actual (Problematic) Behavior
- the URL displayed in the desktop browser UI in the bottom left is always the
window.location.hrefon account of the "link" link havinghref=""(the intended URL is shown viatitleattribute) - Some native browser link interactions like "Right click to open in a new tab" are broken because the
hrefattribute isn't appropriately set to the link target (note, that the playground somehow prevents right clicking on the link, but in a real example, right clicking works) - Activating the link via click works, presumably there's some JavaScript using the value of the
data-hrefattribute which does hold the correct link target
Expected Behavior
- the URL displayed in the desktop browser UI is exactly the link target
- All native browser link interactions are available
- Activating the link via click works
Additional Context
It's not clear why this was done but it should be a straightforward fix.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Monaco Editor Playground reproduction and inspect the hover tooltip link generated from the Markdown contents. Compare its href with the data-href and title values, then verify that the actual link target appears in the browser status bar and that native link actions work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100