2.3 KiB
2.3 KiB
Storybook Importer Cache
- Status:
completed - Owner:
codex - Date:
2026-03-25
Goal
Prevent Storybook from serving a stale Vite importer map after story files are added or removed,
which currently causes runtime failures like importers[path] is not a function even though the
story index already references the new file.
Scope
- In scope:
- diagnose the mismatch between
index.jsonand the virtualstorybook-stories.jsimporter map - update Storybook's Vite cache strategy so story file set changes invalidate the cache
- verify the runtime importer map and story index agree after the config change
- diagnose the mismatch between
- Out of scope:
- changing component implementations or Storybook story content
- broader Storybook architecture changes unrelated to cache invalidation
Constraints
- Keep the repo-local Storybook cache under
.artifacts/. - Prefer invalidating on story file set changes, not on every edit, so normal dev caching remains useful.
- Avoid introducing new package dependencies just to compute a cache key.
Affected Surfaces
docs/exec-plans/2026-03-25-storybook-importer-cache.mdapps/docs/.storybook/main.ts
Plan
- Record the importer/index mismatch and confirm it is cache-related.
- Derive the Storybook Vite cache directory from the current story file set.
- Restart Storybook and verify the virtual importer map matches
index.json.
Validation
pnpm dev:docs- compare
http://127.0.0.1:<port>/index.jsonagainsthttp://127.0.0.1:<port>/@id/__x00__virtual:/@storybook/builder-vite/storybook-stories.js
Status Log
2026-03-25 15:31Confirmed a runtime mismatch:index.jsonreferences./src/components/gauge.stories.tsx, but the cached virtualstorybook-stories.jsimporter map does not include it.2026-03-25 15:38Updated Storybook's Vite cache directory to include a hash of the current story file set so added or removed story files invalidate the cache instead of reusing a stale importer map.2026-03-25 15:42Restarted Storybook and verifiedindex.jsonand the virtual importer map both report 47 story import paths, includinggauge.stories.tsxandinput-group.stories.tsx.2026-03-25 15:47Verifiedpnpm harness:validate:docsandpnpm --dir apps/docs run typecheck; also fixed the localrevenue-dashboardnavigation item typing so docs typecheck returns cleanly.