Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/issue 1257 refine standard CSS plugin intercepting #1262

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -364,7 +364,7 @@
}
}
} else {
// TODO figure out how to handle URL chunk from SSR pages

Check warning on line 367 in packages/cli/src/config/rollup.config.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO figure out how to handle URL chunk...'

Check warning on line 367 in packages/cli/src/config/rollup.config.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected ' TODO' comment: 'TODO figure out how to handle URL chunk...'

Check warning on line 367 in packages/cli/src/config/rollup.config.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO figure out how to handle URL chunk...'

Check warning on line 367 in packages/cli/src/config/rollup.config.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected ' TODO' comment: 'TODO figure out how to handle URL chunk...'
// https://github.com/ProjectEvergreen/greenwood/issues/1163
}

Expand Down Expand Up @@ -530,8 +530,8 @@
// 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
Loading