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

Issues with CSS in development mode #237676

Open
tmm1 opened this issue Jan 10, 2025 · 1 comment
Open

Issues with CSS in development mode #237676

tmm1 opened this issue Jan 10, 2025 · 1 comment
Assignees
Labels
ESM Issues caused by our AMD => ESM work

Comments

@tmm1
Copy link
Contributor

tmm1 commented Jan 10, 2025

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.96.2 / main
  • OS Version: macOS 15.2

There are several issues that impact the developer experience when developing CSS for vscode itself

  1. Load/reload window is very slow

    Image

    this seems to be related to the use of @import url() which appears to download stylesheets serially. switching to <link> tags locally removed this hotspot

  2. CSS changes are not picked up on reload window

    known issue see Ensure "Developer: Reload Window" actually picks up new css file contents #237603 (comment) and fix: disable persistent and in-memory cache when loading resources in oss #234357

    also CSSDevelopmentService caches its list of discovered css files, so if you add or delete a css file things do not work as expected

  3. Full reload is very cumbersome for simple CSS changes

    a Reload CSS option that simply refreshes all the CSS on the page would be much better experience

    automatically reloading CSS based on file-watch events would be ideal

@tmm1
Copy link
Contributor Author

tmm1 commented Jan 10, 2025

it seems like inline-styles are preferred in vscode sources, so CSS devex improvements may not be a priority

but if there is interest in the above i can submit a PR.

the design looks roughly like:

-                       globalThis._VSCODE_CSS_LOAD = function (url) {
-                               style.textContent += `@import url(${url});\n`;
+                       globalThis._VSCODE_CSS_LOAD = function (url: string, cssModule: string, cssHash: string) {
+                               const link = document.createElement('link');
+                               link.rel = 'stylesheet';
+                               link.href = url + '?hash=' + cssHash;
+                               link.type = 'text/css';
+                               link.media = 'screen';
+                               link.id = cssModule.replace('.css', '');
+                               document.head.appendChild(link);
export interface ICSSDevelopmentService {
        _serviceBrand: undefined;
        isEnabled: boolean;
-       getCssModules(): Promise<string[]>;
+       getCssModules(reload?: boolean): Promise<Map<string, string>>;
+       onDidChangeCssModules: Event<Map<string, string>>;
 }
@@ -706,6 +706,19 @@ export class NativeWindow extends BaseWindow {
                if (this.environmentService.enableSmokeTestDriver) {
                        this.setupDriver();
                }
+
+               // CSS Modules
+               this.nativeHostService.onDidChangeCssModules(cssModules => {
+                       for (const [path, hash] of Object.entries(cssModules)) {
+                               const link = mainWindow.document.querySelector(`link[rel="stylesheet"][id="${path.replace('.css', '')}"]`);
+                               if (link) {
+                                       const linkElement = link as HTMLLinkElement;
+                                       const url = new URL(linkElement.href);
+                                       url.searchParams.set('hash', hash);
+                                       linkElement.href = url.toString();
+                               }
+                       }
+               });
        }

@bpasero bpasero added the ESM Issues caused by our AMD => ESM work label Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ESM Issues caused by our AMD => ESM work
Projects
None yet
Development

No branches or pull requests

4 participants