Skip to content

Commit

Permalink
fix: rare case when document passed to dom.scrollbarWidth doesn't h…
Browse files Browse the repository at this point in the history
…ave `documentElement`
  • Loading branch information
mkslanc committed Nov 4, 2022
1 parent 0c49167 commit 469d587
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/ace_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ module.exports = {

ace.config.set("useStrictCSP", false);
assert.ok(getStyleNode());
},
"test: edit template" : function() {
var template = document.createElement("template");
var div = document.createElement("div");
template.content = document.createDocumentFragment();
template.content.appendChild(div);
var fragment = template.content.cloneNode(true);
var el = fragment.firstChild;
//emulating template content document fragment behaviour in browser
//which cause #4634 issue (virtual Document that doesn't have `documentElement`)
el.ownerDocument = {};
var editor = ace.edit(el);
assert.equal(editor.container, el);
editor.destroy();
}
};

Expand Down
10 changes: 6 additions & 4 deletions src/lib/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ exports.importCssString = importCssString;
exports.importCssStylsheet = function(uri, doc) {
exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc));
};
exports.scrollbarWidth = function(document) {
exports.scrollbarWidth = function(doc) {
var inner = exports.createElement("ace_inner");
inner.style.width = "100%";
inner.style.minWidth = "0px";
Expand All @@ -237,21 +237,23 @@ exports.scrollbarWidth = function(document) {

outer.appendChild(inner);

var body = document.documentElement;
var body = (doc && doc.documentElement) || (document && document.documentElement);
if (!body) return 0;

body.appendChild(outer);

var noScrollbar = inner.offsetWidth;

style.overflow = "scroll";
var withScrollbar = inner.offsetWidth;

if (noScrollbar == withScrollbar) {
if (noScrollbar === withScrollbar) {
withScrollbar = outer.clientWidth;
}

body.removeChild(outer);

return noScrollbar-withScrollbar;
return noScrollbar - withScrollbar;
};

exports.computedStyle = function(element, style) {
Expand Down

0 comments on commit 469d587

Please sign in to comment.