diff --git a/packages/critters-webpack-plugin/test/__snapshots__/index.test.js.snap b/packages/critters-webpack-plugin/test/__snapshots__/index.test.js.snap index 32f97ad..16368f3 100644 --- a/packages/critters-webpack-plugin/test/__snapshots__/index.test.js.snap +++ b/packages/critters-webpack-plugin/test/__snapshots__/index.test.js.snap @@ -66,7 +66,7 @@ footer {

My first styled page

Welcome to my styled page!

- + " `; @@ -195,7 +195,7 @@ html {

My first styled page

Welcome to my styled page!

- + " `; @@ -266,7 +266,7 @@ footer {

My first styled page

Welcome to my styled page!

- + " `; @@ -337,7 +337,7 @@ footer {

My first styled page

Welcome to my styled page!

- + " `; diff --git a/packages/critters/src/index.js b/packages/critters/src/index.js index 65aa629..6c575a2 100644 --- a/packages/critters/src/index.js +++ b/packages/critters/src/index.js @@ -24,7 +24,7 @@ import { serializeStylesheet, validateMediaQuery, walkStyleRules, - walkStyleRulesWithReverseMirror, + walkStyleRulesWithReverseMirror } from './css'; import { createLogger, isSubpath } from './util'; @@ -325,7 +325,7 @@ export default class Critters { // skip filtered resources, or network resources if no filter is provided if (this.urlFilter ? this.urlFilter(href) : !href?.endsWith('.css')) { - return Promise.resolve(); + return undefined; } // the reduced critical CSS gets injected into a new - + 0 0 0 4px rgba(10, 132, 255, 0.3)}div:is(:hover, .active){color:#000}div:is(.selected, :hover){color:#fff}body{height:100%} +
@@ -91,3 +91,27 @@ exports[`Critters Skip invalid path 1`] = ` " `; + +exports[`Critters should keep existing link tag attributes 1`] = ` +" + + $title + + + +

Hello World!

+ +" +`; + +exports[`Critters should keep existing link tag attributes in the noscript link 1`] = ` +" + + $title + + + +

Hello World!

+ +" +`; diff --git a/packages/critters/test/critters.test.js b/packages/critters/test/critters.test.js index 1478c9d..2582dd5 100644 --- a/packages/critters/test/critters.test.js +++ b/packages/critters/test/critters.test.js @@ -96,6 +96,67 @@ describe('Critters', () => { expect(result).toMatch('$title'); }); + test('should keep existing link tag attributes in the noscript link', async () => { + const critters = new Critters({ + reduceInlineStyles: false, + path: '/', + preload: 'media' + }); + const assets = { + '/style.css': trim` + h1 { color: blue; } + ` + }; + critters.readFile = (filename) => assets[filename]; + const result = await critters.process(trim` + + + $title + + + +

Hello World!

+ + + `); + + expect(result).toMatch(''); + expect(result).toMatch( + `` + ); + expect(result).toMatchSnapshot(); + }); + + test('should keep existing link tag attributes', async () => { + const critters = new Critters({ + reduceInlineStyles: false, + path: '/', + }); + const assets = { + '/style.css': trim` + h1 { color: blue; } + ` + }; + critters.readFile = (filename) => assets[filename]; + const result = await critters.process(trim` + + + $title + + + +

Hello World!

+ + + `); + + expect(result).toMatch(''); + expect(result).toMatch( + `` + ); + expect(result).toMatchSnapshot(); + }); + test('Does not decode entities in HTML document', async () => { const critters = new Critters({ path: '/'