File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -458,7 +458,7 @@ describe("utils", () => {
458458 expect ( ( sheet as any ) . cssText ) . toBe ( css ) ;
459459
460460 const adopted = ( document as any ) . adoptedStyleSheets as CSSStyleSheet [ ] ;
461- expect ( adopted . includes ( sheet as CSSStyleSheet ) ) . toBe ( true ) ;
461+ expect ( adopted . includes ( sheet ) ) . toBe ( true ) ;
462462 } ) ;
463463
464464 it ( "应该在已有样式表的基础上追加新的样式表" , ( ) => {
@@ -487,7 +487,7 @@ describe("utils", () => {
487487 expect ( ( sheet as any ) . cssText ) . toBe ( "" ) ;
488488
489489 const adopted = ( document as any ) . adoptedStyleSheets as CSSStyleSheet [ ] ;
490- expect ( adopted . includes ( sheet as CSSStyleSheet ) ) . toBe ( true ) ;
490+ expect ( adopted . includes ( sheet ) ) . toBe ( true ) ;
491491 } ) ;
492492
493493 it ( "应该允许添加多个样式表" , ( ) => {
Original file line number Diff line number Diff line change @@ -222,26 +222,14 @@ export function addStyle(css: string): HTMLStyleElement {
222222 return document . documentElement . appendChild ( dom ) ;
223223}
224224
225- export function addStyleSheet ( css : string ) : CSSStyleSheet | HTMLStyleElement {
225+ export function addStyleSheet ( css : string ) : CSSStyleSheet {
226226 // see https://unarist.hatenablog.com/entry/2020/07/06/012540
227- // 旧浏览器(如 Firefox 100 以下)不支持 Constructable Stylesheets / adoptedStyleSheets,回退到 <style> 注入
228- if (
229- typeof CSSStyleSheet === "function" &&
230- typeof CSSStyleSheet . prototype ?. replaceSync === "function" &&
231- Array . isArray ( document . adoptedStyleSheets )
232- ) {
233- try {
234- const sheet = new CSSStyleSheet ( ) ;
235- // it might return as Promise
236- sheet . replaceSync ( css ) ;
237- // adoptedStyleSheets is FrozenArray so it has to be re-assigned.
238- document . adoptedStyleSheets = document . adoptedStyleSheets . concat ( sheet ) ;
239- return sheet ;
240- } catch {
241- // 个别环境下 new CSSStyleSheet() 仍可能抛出,落到 <style> fallback
242- }
243- }
244- return addStyle ( css ) ;
227+ const sheet = new CSSStyleSheet ( ) ;
228+ // it might return as Promise
229+ sheet . replaceSync ( css ) ;
230+ // adoptedStyleSheets is FrozenArray so it has to be re-assigned.
231+ document . adoptedStyleSheets = document . adoptedStyleSheets . concat ( sheet ) ;
232+ return sheet ;
245233}
246234
247235export function metadataBlankOrTrue ( metadata : SCMetadata , key : string ) : boolean {
You can’t perform that action at this time.
0 commit comments