Skip to content

fix(studio): use file watcher for SSR module cache invalidation#11

Merged
cuio merged 1 commit intomainfrom
fix/studio-ssr-cache-watcher
Apr 25, 2026
Merged

fix(studio): use file watcher for SSR module cache invalidation#11
cuio merged 1 commit intomainfrom
fix/studio-ssr-cache-watcher

Conversation

@cuio
Copy link
Copy Markdown
Owner

@cuio cuio commented Apr 25, 2026

Problem

PR #10's apiInvalidatedSince() called require.resolve("@hyperframes/core/studio-api") to find the module's file path. But vite.config.ts is loaded as ESM where require.resolve isn't a function — every API call after the first threw TypeError: __require.resolve is not a function and the studio returned 500s.

Fix

Replaced the module-graph walk with a simpler file-watcher approach:

  • server.watcher.on('change' | 'add') flips an _apiDirty flag whenever any file under packages/core/src or packages/studio/src changes
  • Next getApi() drops the cache and re-runs ssrLoadModule to pick up the new bindings
  • Same end-to-end behaviour as the intended PR feat(script): cinematography agents + hook layering + ssr cache fix #10 fix (source edits propagate without restart), no ESM/CJS pitfalls

Test plan

  • Studio starts cleanly (bun run --cwd packages/studio dev)
  • /api/projects/:id/script/files-status returns 200 instead of 500
  • /api/projects/:id/script returns 200
  • No __require.resolve errors in server logs

PR #10's apiInvalidatedSince() called require.resolve() to find the
studio-api entry path, but vite.config.ts is loaded as ESM where
__require.resolve isn't available — every API call after the first
threw TypeError and the studio returned 500s.

Replaced the module-graph walk with server.watcher.on('change') /
('add'). When any file under packages/core/src or packages/studio/src
changes, mark the api dirty; the next getApi() drops the cache and
re-runs ssrLoadModule. Same end-to-end behaviour (source edits
propagate without restart), no ESM/CJS pitfalls.
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.

1 participant