fix(studio): use file watcher for SSR module cache invalidation#11
Merged
Conversation
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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PR #10's
apiInvalidatedSince()calledrequire.resolve("@hyperframes/core/studio-api")to find the module's file path. Butvite.config.tsis loaded as ESM whererequire.resolveisn't a function — every API call after the first threwTypeError: __require.resolve is not a functionand the studio returned 500s.Fix
Replaced the module-graph walk with a simpler file-watcher approach:
server.watcher.on('change' | 'add')flips an_apiDirtyflag whenever any file underpackages/core/srcorpackages/studio/srcchangesgetApi()drops the cache and re-runsssrLoadModuleto pick up the new bindingsTest plan
bun run --cwd packages/studio dev)/api/projects/:id/script/files-statusreturns 200 instead of 500/api/projects/:id/scriptreturns 200__require.resolveerrors in server logs