Repository navigation
fix(auth): reload the auth config and its local imports in dev - #554
Brooooooklyn wants to merge 4 commits into
Conversation
A native import() keeps the first evaluation of auth.ts, and of every local file it imports, for the life of the process, so the dev server kept regenerating auth files from the config it saw first. The loader still uses Node's own import, so module rules are unchanged (type stripping, top-level await, --conditions; no tsconfig read, NODE_ENV untouched). A resolve hook gives each load a fresh query on the entry and on every local ES module it imports. Packages load once. A load whose files are all unchanged reuses the previous result. Node keeps CommonJS files and anything reached through require() cached by path. They are reported, and the dev server warns that saving one needs a restart. The watcher also reloads on saves to the config's local imports, retries after a failed load, and catches a file saved while a load runs. Fixes #550 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…Chromium Under a full parallel run, launching Chromium can pass the default timeout. The sibling browser tests already allow 30 seconds. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-auth-config-reload-void-cloud.voidzero-docs.workers.dev (commit 5fbd01a)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
|
This looks pretty sketchy tbh. Could this not be a Vite plugin or similar? |
Replace the process-wide Node resolve hook with a dev-only Vite environment, `void_auth_config`: a Node module runner with HMR off. The dev server loads auth.ts through it; Vite's module graph lists the files the config imports, so a save of any of them invalidates those modules and the config is read again. Builds and CLI commands keep the plain import() from before. - Start-up auth migrations load through the same runner, so a restarted dev server also creates new auth tables and columns. - After a failed load, or a save during a load, the next script save retries from a clean environment. The retry runs apart from the save, so a config that still fails does not stop page reloads. - Vite's update pass skips the environment, so saves log no page reload that nothing receives. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@cpojer Fair point, that was a lot of machinery. Replaced in 834ecce: no Node hooks now. In dev, Void declares a small Node-only Vite environment ( Builds and CLI commands ( |
|
@codex review |
|
This is a lot less sketchy. |
Replace the retry state (retry and loading flags, a script extension list, a second load path and the gating around it) with one flag. A save of a file in the auth environment's module graph, or a failed load, marks the config stale; the next load invalidates the whole graph first. After a failed load, a created file triggers that load, as the missing import may now exist. The runner checks each import against the server graph, so clearing the runner cache is not needed. Loads run in order, so a save during a load is picked up by the load queued after it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Fixes #550
Problem
loadVoidAuthConfig()used a nativeimport(). Node keeps the first evaluation of a file, and of every file it imports, until the process exits. So while the dev server ran, the generated auth schema kept using the firstauth.tsit saw.Fix
In dev, Void declares a small Node-only Vite environment,
void_auth_config(only forserve; no HMR client), and loadsauth.tsthrough its module runner:One flag (
authConfigStale) drives it. It's set by a save of a file in the graph, or by a failed load.void prepare,db generate,void build) keep the plainimport()frommain. They run once per process, so caching doesn't matter there.r, or Void's own restart) creates the new tables and columns.Edge cases
auth.tsedit / local helper editmaindoes when the auth config fails to loadVite's own update pass skips this environment (
hotUpdatereturns[]), so saves don't log apage reloadthat nothing receives.Same pattern as Vite and React Router
All APIs used are public exports of
vite8 (Environment API, "release candidate": stable within a major). A plainserver.restart()would not fix #550: Vite restarts in the same process, so Node'simport()cache would survive it.History
The first push used a process-wide
module.registerHooksresolve hook. That needed its own dependency list, content hashes and CommonJS special cases. After review it's replaced by this Vite-based version, which is smaller and only exists in dev.Restart still needed for
New auth tables and columns in the local database. They're created when the dev server starts or restarts, as before. The docs line says so.
Checks
plugin-routing.test.tsdrives a real Vite dev server (no watcher, events sent by hand, plus a slowwatchChangeplugin so the test can't depend on Vite's handler order). It covers:Other tests cover
hotUpdate, and that the environment is declared only forserve(not preview or build).plugin-migration.test.ts: start-up migrations get the dev server's importer.auth-config-loader.test.ts: the exports, the importer, anddevAuthConfigImporteron a real server.Each guard was removed once (mutation check) and a test failed each time: stale on save, stale on failure,
invalidateAll, the created-file reload, and the runner import.On a built CLI in a scratch app,
vp dev:voidpackage typecheck, lint and fmt pass. Affected tests (vp run test --base origin/main, 736 files) pass.The second commit gives the platform status browser test the same 30s timeout as its sibling browser tests. It timed out once under a full parallel run.
Not changed here (older behavior)
auth.tsitself has a syntax error, auth config discovery (findVoidAuthConfig) can't parse it and treats it as "no config", without saying so.auth.tsimports a file that doesn't exist yet, the Worker (void_worker) keeps returning 500 even after the file is created;maindoes the same. The generated schema does recover.🤖 Generated with Claude Code