cssmanager: Refactor CSS manager creation to avoid race condition

Safari takes a while to initialize `document.styleSheets`, which
results in a race condition when loading the pad. Avoid the race
condition by accessing the CSSStyleSheet objects directly from the
HTMLStyleElement DOM objects.
This commit is contained in:
Richard Hansen 2021-03-19 20:50:01 -04:00 committed by John McLear
parent e2bfe2fd10
commit 3ad1d0a74f
5 changed files with 20 additions and 60 deletions

View file

@ -25,6 +25,7 @@
// requires: undefined
const hooks = require('./pluginfw/hooks');
const makeCSSManager = require('./cssmanager').makeCSSManager;
const pluginUtils = require('./pluginfw/shared');
const debugLog = (...args) => {};
@ -307,7 +308,11 @@ const Ace2Editor = function () {
await new Promise((resolve, reject) => innerWindow.plugins.ensure(
(err) => err != null ? reject(err) : resolve()));
debugLog('Ace2Editor.init() waiting for Ace2Inner.init()');
await innerWindow.Ace2Inner.init(info);
await innerWindow.Ace2Inner.init(info, {
inner: makeCSSManager(innerStyle.sheet),
outer: makeCSSManager(outerStyle.sheet),
parent: makeCSSManager(document.querySelector('style[title="dynamicsyntax"]').sheet),
});
debugLog('Ace2Editor.init() Ace2Inner.init() returned');
loaded = true;
doActionsPendingInit();