Skip to content

Conversation

@rise-erpelding
Copy link
Contributor

@rise-erpelding rise-erpelding commented Nov 11, 2025

Summary

Refactors CSS loading to use a modular design system approach by loading individual design token and theme files in ExtensionManager.js instead of a monolithic styles file, then removes the now-unused styles.css file for cleaner project structure.

BLDL-25

Problem

The extension was loading styles from a single styles.css file that contained @import statements with Chrome-specific chrome-extension:// URLs. This caused styles to fail loading in Firefox, which uses the moz-extension:// protocol instead.

Solution

Split the monolithic approach into a modular design system:

  1. Modified ExtensionManager.loadCoreCSS() to load design tokens and themes individually
  2. Deleted unused src/styles/styles.css - The old file with @import statements is no longer needed

All files are loaded via JavaScript using browserAPI.runtime.getURL(), which handles browser-specific protocols automatically, ensuring cross-browser compatibility.

Testing

  • Build process completes successfully
  • When inspecting the page, <style> tags in the page's <head> with carbon-visualizer- prefixed ids are visible.
  • Tested in Firefox - styles now load correctly
  • No changes to Chrome functionality
  • All design tokens properly available to panels

@github-actions
Copy link

github-actions bot commented Nov 11, 2025

📦 Extension packages built successfully!

Download your Chrome and Firefox extension packages

@rise-erpelding rise-erpelding self-assigned this Nov 18, 2025
@rise-erpelding rise-erpelding marked this pull request as ready for review November 18, 2025 18:40
@rise-erpelding rise-erpelding changed the title fix: adjust css file paths fix: adjust css file loading Nov 18, 2025
Copy link
Contributor

@dustin-jw dustin-jw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything works in Firefox and Chrome, but there are a couple areas that could be cleaned up a bit. I like the approach with grouping together all the common CSS things in JS though, nice work!

// Add a marker to indicate core CSS bundle is loaded
const marker = document.createElement('style');
marker.id = 'carbon-visualizer-core-css-bundle';
marker.textContent = '/* Core CSS bundle loaded */';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we refactor this so we just have the one style tag with #carbon-visualizer-core-css-bundle that contains all the styles from the other files? As-is, we get 6 other unidentified style tags that are harder to find when debugging.

let css = '';
for (const file of files) {
  const cssUrl = this.browserAPI.runtime.getURL(file);
  const response = await fetch(cssUrl);
  css += await response.text();
}

const style = document.createElement('style');
style.textContent = css;
style.id = 'carbon-visualizer-core-css-bundle';
document.head.appendChild(style);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we think about a style tag for the bundle, then adding one for the css for each panel?

I'm not sure performance-wise it makes a huge difference whether you throw all the panel styles in the bundle or keep them separate. It just felt slightly more logical to have panel styles separate, but it seems reasonable to bundle them too, so I'm on the fence and happy to go either way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy to lump them all together. Keeping them separated is more useful on the authoring side, but bundling them on the consuming side should be fine, and it would simplify Panel.js a bit.

results: {
htmlFile: 'src/panels/results/results.html',
cssFile: 'src/panels/results/results.css',
cssFile: 'src/styles/results.css',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically out of scope, but I found that every time I changed the panel, like toggling between welcome and results, it would add another redundant style tag with the same ID.

Image

We could add a check at the start of loadPanelCSS() to avoid injecting CSS that has already been loaded, the same way loadCoreCSS does.

Copy link
Contributor

@dustin-jw dustin-jw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @rise-erpelding!

@dustin-jw dustin-jw merged commit 32e8117 into main Dec 2, 2025
1 check passed
@dustin-jw dustin-jw deleted the fix--bldl-25-firefox-styles branch December 2, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants