Repository navigation
fix: wait for stylesheets to be loaded before adopting them - #834
Merged
Merged
Conversation
On Firefox, a constructed CSSStyleSheet stays "still-loading" until its replace() promise settles, and reading its cssRules throws an InvalidAccessError. Browser extensions that proxy the adoptedStyleSheets setter (e.g. Dark Reader) read cssRules from the setter, so adopting the sheets right after registering them made initialize() reject and the editor never load. Refs darkreader/darkreader#14329 Co-authored-by: Cursor <cursoragent@cursor.com>
CGNonofr
reviewed
Oct 19, 2026
samuel-olivier
force-pushed
the
fix/wait-for-css-before-adopting
branch
from
October 19, 2026 15:48
3455f48 to
11323f8
Compare
The font face sheet is built synchronously with insertRule inside the then of its own sheet promise, so it is never still-loading and there is no need to wait for the other sheets before adopting it on the document. Co-authored-by: Cursor <cursoragent@cursor.com>
CGNonofr
reviewed
Oct 19, 2026
CGNonofr
self-requested a review
October 19, 2026 16:18
CGNonofr
approved these changes
Oct 19, 2026
|
🎉 This PR is included in version 38.0.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since #825 (
d16f931),registerCsscreates constructed stylesheets with the asyncCSSStyleSheet.replace(), andinjectCss()adopts them right away at the start ofinitialize().On Firefox, a constructed sheet stays "still-loading" until its
replace()promise settles, and reading itscssRulesin the meantime throwsInvalidAccessError: Can't access rules of still-loading style sheet. Browser extensions that proxy theadoptedStyleSheetssetter readcssRuleson each adopted sheet — Dark Reader does (isDRAdoptedSheetOverride→onAdoptedSheetsChange, upstream issue darkreader/darkreader#14329). The setter throws,initialize()rejects.Fix
src/css.ts: keep everyreplace()promise insheetPromises;whenSheetsLoaded()isPromise.allSettledover them.injectCss()becomesasyncand awaitswhenSheetsLoaded()before settingroot.adoptedStyleSheets.@font-facesheet adopted ondocumentis deferred the same way.src/services.ts:initialize()nowawaitsinjectCss(container)(it was already async, so no API change for callers).Validation
Repro loading the editor with Dark Reader's
adoptedStyleSheetsproxy injected:InvalidAccessErroron adoption,initialize()rejects.