Repository navigation
Reload env on the first Vite dev restart when root is not the cwd - #1262
Merged
theoephraim merged 2 commits intoOct 30, 2026
Merged
Conversation
When the first config hook call reloads from a root that differs from the loaded directory, it did not set configHookCalled. The next call, the first dev restart, then took the first-call branch and skipped its reload, so the server kept stale env values until the second restart. Fixes dmno-dev#1261
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes Reviewed the restart-state fix, both regression tests, and the patch release entry.
- Restart tracking: Marks the first root-correcting config reload as a completed hook call so the next dev restart reloads env values.
- Regression coverage: Tests repeated config resolution for a Vite root outside cwd and for
rootDirwith an existing encryption key. All 26 Vite integration tests passed viabunx turbo run test:ci --filter=@varlock/vite-integration; filesystem-watched restarts were not independently exercised. - Release scope: Includes a patch release entry for
@varlock/vite-integration.
gpt-6.1-sol | 𝕏
Member
|
thanks for this! |
commit: |
Every load marks itself unused and the main config hook consumes it, so any loader (module-level, dev-key hook, an integration's refresh) counts without its own flag. This also drops the second load on Nuxt dev restarts. Adds restart tests that assert load counts.
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes Reviewed the load-consumption refactor and added regression coverage since the previous review.
- Replaced restart tracking: Tracked whether the current load has been consumed by the config hook, preserving first-restart reloads while reusing a preceding framework refresh.
- Expanded regression coverage: Added load-count checks for repeated resolves, dev-key root correction, Nuxt-style refreshes, and same-root builds. All 31 Vite integration tests passed via
bunx turbo run test:ci --filter=@varlock/vite-integration; filesystem-watched restarts were not independently exercised.
gpt-6.1-sol | 𝕏
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.

Fixes #1261.
When Vite's root is not the working directory (for example
vite app), the firstconfighook call reloads from that root, but it does not setconfigHookCalled. On the first dev restart, the root now equalsloadedConfigDir, so the hook takes the first-call branch: it sets the flag and skips the reload. The server keeps stale env values until the second restart. This started in 1.5.0 with #985, which changed the check fromprocess.cwd()toloadedConfigDir. The same stale restart happens withrootDirwhen_VARLOCK_ENV_KEYis already set, because then the dev-key lifecycle hook does not loadrootDirbefore the main hook.The fix replaces
configHookCalledwith a flag that every load sets and the main config hook clears once it has used that load. The hook reloads when the root differs, or on a dev resolve when the current load was already used (a restart). Any loader (the module-level load, the dev-key hook, an integration's refresh) now counts without needing its own flag. This also removes the second load on Nuxt dev restarts, whererefreshVarlockEnvalready reloaded before the config hook.Tests cover restarts with the root equal to and different from the cwd,
rootDirwith and without a preset key, Nuxt-style refreshes, and builds, and assert load counts so redundant or skipped reloads show up.One behavior change: in a dev or Vitest run whose first config has a different root, a later
configcall with the same root now reloads. That already happens when the root is the working directory.