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

fix(web-components): fix WICG issue importing styles #336

Merged
merged 1 commit into from
Jul 31, 2024
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
10 changes: 8 additions & 2 deletions packages/brisa/src/utils/brisa-element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ export default function brisaElement(
// Add global CSS to apply to the shadowRoot
const css: string[] = [];
for (const sheet of $document.styleSheets) {
if (sheet.href) css.push(`@import url('${sheet.href}');`);
else for (const rule of sheet.cssRules) css.push(rule.cssText);
try {
for (const rule of sheet.cssRules) css.push(rule.cssText);
} catch (e) {
// We only want to @import() when there aren't any rules, otherwise
// it's a WICG issue:
// https://github.com/WICG/construct-stylesheets/issues/119#issuecomment-588352418
css.push(`@import url('${sheet.href}');`);
}
}
sheet.replaceSync(css.join(''));
shadowRoot.adoptedStyleSheets.push(sheet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const pageWebComponents = {
};

const i18nCode = 3072;
const brisaSize = 5949; // TODO: Reduce this size :/
const brisaSize = 5947; // TODO: Reduce this size :/
const webComponents = 792;
const unsuspenseSize = 217;
const rpcSize = 2479; // TODO: Reduce this size
const rpcSize = 2477; // TODO: Reduce this size
const lazyRPCSize = 4188; // TODO: Reduce this size
// lazyRPC is loaded after user interaction (action, link),
// so it's not included in the initial size
Expand Down
Loading