@@ -196,7 +196,7 @@ export class Utils {
196196 * @param parent to insert the stylesheet as first child,
197197 * if none supplied it will be appended to the document head instead.
198198 */
199- static createStylesheet ( id : string , parent ?: HTMLElement , options ?: { nonce ?: string } ) : CSSStyleSheet {
199+ static createStylesheet ( id : string , parent ?: HTMLElement , options ?: { nonce ?: string } ) : HTMLStyleElement {
200200 const style : HTMLStyleElement = document . createElement ( 'style' ) ;
201201 const nonce = options ?. nonce
202202 if ( nonce ) style . nonce = nonce
@@ -216,7 +216,7 @@ export class Utils {
216216 } else {
217217 parent . insertBefore ( style , parent . firstChild ) ;
218218 }
219- return style . sheet as CSSStyleSheet ;
219+ return style ;
220220 }
221221
222222 /** removed the given stylesheet id */
@@ -227,12 +227,10 @@ export class Utils {
227227 }
228228
229229 /** inserts a CSS rule */
230- static addCSSRule ( sheet : CSSStyleSheet , selector : string , rules : string ) : void {
231- if ( typeof sheet . addRule === 'function' ) {
232- sheet . addRule ( selector , rules ) ;
233- } else if ( typeof sheet . insertRule === 'function' ) {
234- sheet . insertRule ( `${ selector } {${ rules } }` ) ;
235- }
230+ static addCSSRule ( sheet : HTMLStyleElement , selector : string , rules : string ) : void {
231+ // Rather than using sheet.insertRule, use text since it supports
232+ // gridstack node reparenting around in the DOM
233+ sheet . textContent += `${ selector } { ${ rules } } ` ;
236234 }
237235
238236 // eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments