Skip to content

Commit

Permalink
better refine when standard CSS plugin should intercept (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Aug 8, 2024
1 parent 2d7f762 commit 390d7a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ function greenwoodSyncImportAttributes(compilation) {
// since we can't do async work inside a sync AST operation
if (!asset.preBundled) {
const assetUrl = unbundledAssetsRefMapper[asset].sourceURL;
const request = new Request(assetUrl, { headers: { 'Content-Type': 'text/css' } });
let response = new Response(unbundledAssetsRefMapper[asset].source);
const request = new Request(assetUrl, { headers: { 'Accept': 'text/css' } });
let response = new Response(unbundledAssetsRefMapper[asset].source, { headers: { 'Content-Type': 'text/css' } });

for (const plugin of resourcePlugins) {
if (plugin.shouldPreIntercept && await plugin.shouldPreIntercept(assetUrl, request, response.clone())) {
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/plugins/resource/plugin-standard-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,13 @@ class StandardCssResource extends ResourceInterface {
});
}

async shouldIntercept(url) {
async shouldIntercept(url, request, response) {
const { pathname } = url;
const ext = pathname.split('.').pop();

return url.protocol === 'file:' && ext === this.extensions[0];
return url.protocol === 'file:'
&& ext === this.extensions[0]
&& (response.headers.get('Content-Type')?.indexOf('text/css') >= 0 || request.headers.get('Accept')?.indexOf('text/javascript') >= 0);
}

async intercept(url, request, response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export default class HeroBanner extends HTMLElement {
}

this.shadowRoot.adoptedStyleSheets = [sheet];
// TODO upstream to WCC?
// this.shadowRoot.querySelectorAll('button')
// .forEach(button => {
// button.addEventListener('click', () => this.clickButton(button))
// });
}
}

Expand Down

0 comments on commit 390d7a1

Please sign in to comment.