@@ -34,16 +34,14 @@ export async function transformCSS(
3434 inlineStyles ?: Map < HTMLElement , Record < string , string > > ,
3535 cleanup = false ,
3636) {
37- const updatedStyleData : StyleData [ ] = [ ] ;
3837 styleData . forEach ( async ( data ) => {
39- const { el, css, changed, original } = data ;
40- const updatedObject : StyleData = { el, css, changed : false , original } ;
41- if ( changed ) {
38+ const { el, css, changed, updated } = data ;
39+ if ( changed && ! updated ) {
4240 if ( el . tagName . toLowerCase ( ) === 'style' ) {
4341 // Handle inline stylesheets
4442 el . innerHTML = css ;
4543 } else if ( el . tagName . toLowerCase ( ) === 'link' ) {
46- updatedObject . el = await replaceLink ( el as HTMLLinkElement , css ) ;
44+ data . el = await replaceLink ( el as HTMLLinkElement , css ) ;
4745 } else if ( el . hasAttribute ( INLINE_STYLES_ID_ATTR ) ) {
4846 // Handle inline styles
4947 const attr = el . getAttribute ( INLINE_STYLES_ID_ATTR ) ;
@@ -62,12 +60,11 @@ export async function transformCSS(
6260 el . setAttribute ( 'style' , styles ) ;
6361 }
6462 }
63+ data . updated = true ;
6564 }
6665 // Remove no-longer-needed data-attribute
6766 if ( cleanup && el . hasAttribute ( INLINE_STYLES_ID_ATTR ) ) {
6867 el . removeAttribute ( INLINE_STYLES_ID_ATTR ) ;
6968 }
70- updatedStyleData . push ( updatedObject ) ;
7169 } ) ;
72- return updatedStyleData ;
7370}
0 commit comments