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]: HMR is broken for bundled CSS in Storybook v8 with Vite #26812

Closed
Th3S4mur41 opened this issue Apr 11, 2024 · 6 comments
Closed

[Bug]: HMR is broken for bundled CSS in Storybook v8 with Vite #26812

Th3S4mur41 opened this issue Apr 11, 2024 · 6 comments

Comments

@Th3S4mur41
Copy link

Th3S4mur41 commented Apr 11, 2024

Describe the bug

After upgrading to v8, HMR is no longer working for imported bundled CSS

Storybook needs to be restarted in order to see the changes

To Reproduce

https://stackblitz.com/edit/storybook-issue-26881

Note

index.css is being compiled in a separate process with a watcher.

preview.ts

import type { Preview } from '@storybook/web-components';

import '/dist/index.css';

const preview: Preview = {
	parameters: {}
};

export default preview;

System

Storybook Environment Info:

  System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  Binaries:
    Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.1 - C:\src\@eviden-parallel\core\node_modules\.bin\npm.CMD <----- active
  Browsers:
    Edge: Chromium (123.0.2420.81)
  npmPackages:
    @storybook/addon-a11y: ^8.0.5 => 8.0.6
    @storybook/addon-designs: ^8.0.0 => 8.0.0
    @storybook/addon-docs: ^8.0.5 => 8.0.6
    @storybook/addon-essentials: ^8.0.5 => 8.0.6
    @storybook/addon-links: ^8.0.5 => 8.0.6
    @storybook/addon-mdx-gfm: ^8.0.5 => 8.0.6
    @storybook/blocks: ^8.0.5 => 8.0.6
    @storybook/theming: ^8.0.5 => 8.0.6
    @storybook/web-components: ^8.0.5 => 8.0.6
    @storybook/web-components-vite: ^8.0.5 => 8.0.6
    storybook: ^8.0.5 => 8.0.6

Additional context

No response

@Th3S4mur41 Th3S4mur41 changed the title [Bug]: HMR is broken for bundled CSS in Storybook v8 [Bug]: HMR is broken for bundled CSS in Storybook v8 with Vite May 16, 2024
@shilman
Copy link
Member

shilman commented May 19, 2024

Probable dupe of #26881

@shilman shilman closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2024
@Th3S4mur41
Copy link
Author

@shilman if reloading is sufficient to get the latest update is sufficient to workaround the issue in #26881, then this is not a duplicate...

In this case here, the only way to get the latest CSS is to restart the server.
Reloading (even force reload), is not sufficient.

@shilman
Copy link
Member

shilman commented May 21, 2024

@Th3S4mur41 my bad, thanks for clarifying! Re-opening

@shilman
Copy link
Member

shilman commented May 21, 2024

Fyi @valentinpalkovic - possibly related to your other issues but not a duplicate

@valentinpalkovic
Copy link
Contributor

After debugging and trying a few things, Vite seems to ignore files in dist folders (at least they are not watched) and, therefore, does not trigger an HMR event. If you rename dist to something else, HMR and watching the file works :)

I don't know whether we can do anything about this. Therefore, I would close this issue.

@valentinpalkovic valentinpalkovic closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
@Th3S4mur41
Copy link
Author

I've tried to fix it using a bunch of of wayt to configure the watcher setting of the vite config like e.g.

// vite.config.mjs
import { defineConfig } from 'vite';

export default defineConfig({
build: {
    watch: {
			exclude: ['node_modules'],
      include: ['src/**', 'dist/**']
    }
  }
});

Unfortunately, that didn't work. This is probably related to vitejs/vite#8619

Changing the output of my postcss to the build folder and loading the CSS in preview.ts from there as suggested by @valentinpalkovic required some changes in the various build and release scripts, but did solve the issue.
So thanks for the workaround 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants