Skip to content

Commit

Permalink
Fix: join srcset in source with ", " (#7918)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Apr 11, 2022
1 parent 39b330e commit fdeb508
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/core/integration-tests/test/html.js
Expand Up @@ -834,6 +834,12 @@ describe('html', function () {
assets: ['300x300.png'],
},
]);

const html = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');

const source = html.match(/<source srcset=".*>/)[0];

assert(source.split(', ').length === 3);
});

it('should detect imagesrcset attribute', async function () {
Expand Down
8 changes: 7 additions & 1 deletion packages/transformers/html/src/dependencies.js
Expand Up @@ -96,7 +96,13 @@ function collectSrcSetDependencies(asset, srcset, opts) {
newSources.push(pair.join(' '));
}

return newSources.join(',');
/**
* https://html.spec.whatwg.org/multipage/images.html#srcset-attribute
*
* If an image candidate string in srcset contains a width descriptor or a pixel density descriptor or ASCII whitespace, the following image candidate string must begin with whitespace.
* So we need to join each image candidate string with ", ".
*/
return newSources.join(', ');
}

function getAttrDepHandler(attr) {
Expand Down

0 comments on commit fdeb508

Please sign in to comment.