mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
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:
parent
e2bfe2fd10
commit
3ad1d0a74f
5 changed files with 20 additions and 60 deletions
|
@ -22,34 +22,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const makeCSSManager = (emptyStylesheetTitle, doc) => {
|
||||
if (doc === true) {
|
||||
doc = 'parent';
|
||||
} else if (!doc) {
|
||||
doc = 'inner';
|
||||
}
|
||||
|
||||
const getSheetByTitle = (title) => {
|
||||
let win;
|
||||
if (doc === 'parent') {
|
||||
win = window.parent.parent;
|
||||
} else if (doc === 'inner') {
|
||||
win = window;
|
||||
} else if (doc === 'outer') {
|
||||
win = window.parent;
|
||||
} else {
|
||||
throw new Error('Unknown dynamic style container');
|
||||
}
|
||||
for (const s of win.document.styleSheets) {
|
||||
if (s.title === title) return s;
|
||||
}
|
||||
const err = new Error(`no sheet with title ${title} in doc ${doc}`)
|
||||
console.error(err);
|
||||
throw err;
|
||||
};
|
||||
|
||||
const browserSheet = getSheetByTitle(emptyStylesheetTitle);
|
||||
|
||||
exports.makeCSSManager = (browserSheet) => {
|
||||
const browserRules = () => (browserSheet.cssRules || browserSheet.rules);
|
||||
|
||||
const browserDeleteRule = (i) => {
|
||||
|
@ -97,5 +70,3 @@ const makeCSSManager = (emptyStylesheetTitle, doc) => {
|
|||
info: () => `${selectorList.length}:${browserRules().length}`,
|
||||
};
|
||||
};
|
||||
|
||||
exports.makeCSSManager = makeCSSManager;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue