addon-kit: [Bug] HMR for manager code doesn't work, so addon-kit's watch mode doesn't do as much as expected
Describe the bug
Watch mode (aka live reload) is broken for me. My setup: macOS 12.6.3, Node v16.14.0. When I change the code, Storybook in browser doesn’t show the change.
Maintainers’ notes: the issue is not with
build:watchin theaddon-kitbut with the lack of HMR for manager code in Storybook itself.
Steps to reproduce the behavior
- Clone this repo on macOS 12.6.3, Node v16.14.0.
- Run
yarn install - Run
yarn start - Change any displayable value in
src/Tool.tsx - Save file
- Elevator music playing
- Nothing is changed in browser.
Expected behavior
Changes in the code are reflected in running Storybook instance without reloading Storybook manually.
Environment
- OS: macOS 12.6.3
- Node.js version: v16.14.0
- NPM version: 9.2.0
- Browser (if applicable): chrome, safari, firefox
- Browser version (if applicable): n/a
- Device (if applicable): MacBook Pro 2015
Additional context
No other context. Thanks for your work, colleagues.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 12
- Comments: 21 (5 by maintainers)
Commits related to this issue
- chore: watch-mode improvements, https://github.com/storybookjs/addon-kit/issues/49 — committed to AriPerkkio/storybook-addon-aria-live by AriPerkkio 3 years ago
- chore: watch-mode improvements, https://github.com/storybookjs/addon-kit/issues/49 — committed to AriPerkkio/storybook-addon-aria-live by AriPerkkio 3 years ago
@winkerVSbecks I think @SpookyJelly is talking about developer experience. I can make addon without live reload, like in good old times. But it’s wrong. The mission of Storybook is to make devs and designers life easier, not harder.
Investigated this a bit more, and turns out that this is a limitation with Storybook 7.
In SB7, the manager is pre-bundled. The watch mode works and the generated code is updated, but Storybook doesn’t rebuild the manager. In SB6, we could disable the cache to refresh the manager on each build.
Prebundling was a major perf boost for Storybook users, but unfortunately, it made addon development a bit more challenging. I’m looking at other options. Will let you all know if I figure something out.
Hey folks,
I’ve discussed this a bit with maintainers and here’s where we’re at:
addon-kitworks as expected: it watches your addon source code and rebuilds itmanagerEntriesof loaded addons and likely themanager*files in.storybook) and rebuild the manager when they change, so that Storybook would no longer need to be manually restartedmanagerEntriescontain imperative code that may have side effectsContributions are welcome. The Core Team expect this contribution to be feasible by an external contributor, but difficult. Reach out on Discord if you need help with contributing.
I’m going to update the issue a little bit to reflect on what’s working and what needs to be addressed.
It’s been a year and I don’t think it’s been resolved yet, has anyone found another way?
This still seems to be an issue ^, it’s a real pain!
This is a regression for sure. We dropped the hmr code from index.ts:
The reason we dropped hmr was to avoid shipping addons with hmr. I’ll look into adding it back in for dev mode.
Adding custom
tsuphook that restarts the storybook dev server improves developer experience a bit. You’ll still have to manually refresh the browser, but at least changes are reloaded automatically:Do we have any ideas how to work around this with SB 7? I’ve tried several things on my end, but they’ve all failed. Local addons are still parsed (I’m using
.tsx), but the HMR isn’t there…@morewings Sure, I followed the tutorial below. In here, author used the eject command to convert the boilerplate code to JavaScript.
https://storybook.js.org/tutorials/create-an-addon/react/en/getting-started/