Skip to content

Only re-resolve env on Vite/Nuxt dev restarts when env files changed - #1270

Merged
theoephraim merged 4 commits into
mainfrom
nuxt-skip-close-env-refresh
Nov 3, 2026
Merged

theoephraim merged 4 commits into
mainfrom
nuxt-skip-close-env-refresh

Conversation

@theoephraim

@theoephraim theoephraim commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #1249.

Nuxt's dev close hook fires on both reloads and final shutdown (Ctrl+C), and nothing tells them apart. The module forced an env refresh in it, so every quit re-ran resolvers and could re-trigger auth prompts (e.g. 1Password). Dev restarts also loaded env several times each.

The fix makes "is the loaded env still fresh?" a single check, owned by core:

  • varlock core: the serialized graph now records absentSourcePaths (auto-load candidates like .env.local and allowMissing imports that were not found). New checkEnvSourceDrift(graph), exported as varlock/env-source-fingerprint, re-hashes each source against its recorded contentHash and checks whether any absent path now exists. It reads and hashes files only, no parsing or resolution. Injected-env reuse uses it too, so creating .env.local under varlock run is no longer missed.
  • vite integration: new ensureVarlockEnvFresh(rootDir) reloads only when env files drifted. Dev config resolution uses it instead of the loadIsUnconsumed flag. At startup it adopts the graph varlock/auto-load already resolved (same dir only), and a telemetry option change no longer triggers a reload. refreshVarlockEnv stays a forced reload.
  • nuxt integration: both restart and close call ensureVarlockEnvFresh, so a quit or a nuxt.config-only reload resolves nothing.

Checked in a Nuxt 4.6.3 / @nuxt/cli 4.0.1 app with an exec() resolver that logs each run:

Scenario Before After
Startup 4 1
Ctrl+C quit (plain and under varlock run) 1 0
Edit .env.schema 3 1
Create .env 4 1

A nuxt.config edit, with or without a new .env.example, now resolves nothing. Served values and config-time reads are correct after every change.

Behavior change: a dev restart with no env file change (including the r shortcut) no longer re-fetches remote values (vaults, exec(), 1Password Environments FIFOs). Stop and start the dev server to pick those up. Documented in the vite and nuxt guides.

The close hook also fires on final shutdown (Ctrl+C), so every quit re-resolved
the env, re-running plugin resolvers and re-triggering auth prompts such as
1Password. It now refreshes only when the env files differ from what the
instance loaded: loaded sources plus any .env* file next to them, so a newly
created .env still refreshes on the CLI's direct reload path.

Fixes #1249
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • @varlock/astro-integration 1.4.5 → 1.4.6 (cascade)
  • @varlock/cloudflare-integration 1.6.3 → 1.6.4 (cascade)
  • @varlock/native-helper-darwin 1.24.0 → 1.24.1
  • @varlock/native-helper-linux-arm64 1.24.0 → 1.24.1
  • @varlock/native-helper-linux-x64 1.24.0 → 1.24.1
  • @varlock/native-helper-win32-x64 1.24.0 → 1.24.1
  • @varlock/nuxt-integration 0.1.5 → 0.1.6
  • @varlock/vite-integration 1.5.5 → 1.5.6
  • varlock 1.24.0 → 1.24.1

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

varlock

npm i https://pkg.pr.new/varlock@1270

@varlock/astro-integration

npm i https://pkg.pr.new/@varlock/astro-integration@1270

@varlock/cloudflare-integration

npm i https://pkg.pr.new/@varlock/cloudflare-integration@1270

@varlock/nuxt-integration

npm i https://pkg.pr.new/@varlock/nuxt-integration@1270

@varlock/vite-integration

npm i https://pkg.pr.new/@varlock/vite-integration@1270

@varlock/native-helper-darwin

npm i https://pkg.pr.new/@varlock/native-helper-darwin@1270

@varlock/native-helper-linux-arm64

npm i https://pkg.pr.new/@varlock/native-helper-linux-arm64@1270

@varlock/native-helper-linux-x64

npm i https://pkg.pr.new/@varlock/native-helper-linux-x64@1270

@varlock/native-helper-win32-x64

npm i https://pkg.pr.new/@varlock/native-helper-win32-x64@1270

@varlock/1password-plugin

npm i https://pkg.pr.new/@varlock/1password-plugin@1270

@varlock/bitwarden-plugin

npm i https://pkg.pr.new/@varlock/bitwarden-plugin@1270

@varlock/keepass-plugin

npm i https://pkg.pr.new/@varlock/keepass-plugin@1270

@varlock/pass-plugin

npm i https://pkg.pr.new/@varlock/pass-plugin@1270

@varlock/proton-pass-plugin

npm i https://pkg.pr.new/@varlock/proton-pass-plugin@1270

commit: 6bf4bea

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Config-only reloads can now read one env snapshot in nuxt.config.ts and resolve another during Vite setup. The unchanged-env decision needs to carry through to the composed Vite plugin.

Reviewed changes: Reviewed the file-fingerprint guard, Nuxt lifecycle hooks, regression tests, and documentation, including their interaction with Vite's reload state.

  • Shutdown guard: Captures env-file metadata during dev setup and skips the close-hook refresh when nothing changed, while retaining restart deduplication.
  • Regression coverage: Adds creation, modification, and unchanged-shutdown tests; all 17 Nuxt tests and 31 Vite tests passed after generating the parser prerequisite.
  • Documented behavior: Updates the dev-server guidance and release note to describe reuse on shutdown and unchanged-env reloads.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

Comment thread packages/integrations/nuxt/src/index.ts Resolved
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website 6bf4bea Commit Preview URL

Branch Preview URL
Nov 03 2026, 08:46 PM

Replace the consumed-load flag with a stat fingerprint of the env files a load
could read. Dev restarts and the new ensureVarlockEnvFresh() only re-resolve
when an env file changed or appeared, or the last load failed, so a
config-only reload keeps the snapshot its config was evaluated against.

The Nuxt module calls ensureVarlockEnvFresh() from both reload hooks instead of
fingerprinting itself, which also replaces its restart/close dedupe flag.

Startup adopts a graph varlock/auto-load already resolved from the same
directory, and a telemetry name change no longer reloads. A Nuxt dev server
now resolves env once at startup instead of four times.
checkEnvSourceDrift (varlock/env-source-fingerprint) re-hashes each recorded
file source against the contentHash taken when it was parsed, and checks the
new absentSourcePaths list: auto-load candidates and allowMissing imports a load
looked for and did not find. Creating one of those now counts as drift, which
closes the documented gap in injected-env reuse.

The vite integration uses it for dev-restart freshness instead of its own
mtime fingerprint, so an edit made during a slow load is still caught and an
unrelated .env.example no longer triggers a reload.
@theoephraim theoephraim changed the title Skip the Nuxt dev env refresh on shutdown when no env file changed Only re-resolve env on Vite/Nuxt dev restarts when env files changed Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle size

⚠️ grows the bundle by 9.0 KB (+0.2%)

Metric main This PR Δ
Total dist 5178.5 KB 5187.5 KB +9.0 KB (+0.2%)
JS 1977.1 KB 1979.2 KB +2.1 KB (+0.1%)
Sourcemaps 3064.3 KB 3067.6 KB +3.4 KB (+0.1%)
Type defs 137.1 KB 140.6 KB +3.5 KB (+2.6%)
Other 0.0 KB 0.0 KB —

dist/ only; native binaries are versioned separately and not counted here.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes: Reviewed the changes since f1b1b1fd, including shared source-drift detection, Vite snapshot reuse, and Nuxt lifecycle coordination.

  • Centralized drift detection: Added recorded absent-source paths and a shared content-hash check, also used by injected-env reuse to detect newly created env files.
  • Unified dev freshness: Replaced Vite's consumed-load flag with conditional refresh and routed both Nuxt reload hooks through it, preserving the same snapshot across unchanged config reloads.
  • Reduced startup resolution: Adopted same-directory auto-loaded graphs and stopped reloading solely for integration telemetry changes.
  • Expanded regression coverage: Added freshness and startup tests plus documentation; 41 Vite, 14 Nuxt, and 59 focused core tests passed after building test prerequisites. No end-to-end Nuxt/1Password reproduction was run.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@theoephraim
theoephraim merged commit 79fafc7 into main Nov 3, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid re-resolving 1Password secrets on Nuxt dev-server shutdown

1 participant