fix: assorted bug fixes (close #588)#608
Open
andriytyurnikov wants to merge 4 commits intoElMassimo:mainfrom
Open
fix: assorted bug fixes (close #588)#608andriytyurnikov wants to merge 4 commits intoElMassimo:mainfrom
andriytyurnikov wants to merge 4 commits intoElMassimo:mainfrom
Conversation
ElMassimo#588) The plugin was setting `build.sourcemap = !isLocal`, which inverted Vite's safe default: - production / staging → sourcemap=true (publishes .js.map publicly, exposing application source code) - development / test → sourcemap=false (breaks debugging where you'd actually want sourcemaps) Drop the override entirely. Vite's default (`false`) now applies in every mode, and consumers opt in to sourcemaps via `build.sourcemap` in their own vite.config when they actually want them — for production via external upload to e.g. Sentry, or for development debugging. The unit test in vite-plugin-ruby/tests/index.spec.ts had been encoding the inverted behavior; updated to assert `sourcemap` is no longer set by the plugin. The integration test in vite-plugin-rails drops the `.map` entries from the expected file list since the example build no longer emits them.
The example used a TypeScript non-null assertion on process.env.ADMINISTRATOR_ASSETS_PATH that is unset at build time when no Rails engine is wired up, leaving [undefined] in server.fs.allow and an alias resolving to "undefined/...". Vite ≤7 silently tolerated those undefined entries; Vite 8 strictly path-resolves server.fs.allow and crashes with "paths[1] argument must be of type string". Make both the alias and the fs.allow entry conditional on the env var actually being present, so the build works whether or not the engine fixture is wired up.
…fallback Without the explicit return, control falls through to next() after the response has already been ended, allowing downstream middleware to write to a closed response.
The prior implementation read `@running` and wrote `@running_checked_at` without synchronization, so a cold concurrent call from a multi-threaded server (e.g. Puma) could read `@running` after it was set but before `@running_checked_at` was, and the subsequent `Time.now - @running_checked_at` on the next call could raise NoMethodError on nil. Wrap the check-or-refresh in `@running_mutex.synchronize` so the cache read and write are atomic.
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.
First slice of #607, per your request to break it up. Four independent bug fixes, each in its own commit. No version bumps, no CI changes.
Fixes
vite-plugin-ruby: stop forcingsourcemap=truein production (closes #588)The plugin was setting
build.sourcemap = !isLocal, which inverted Vite's safe default:sourcemap=true(publishes.js.mappublicly, exposing source)sourcemap=false(breaks debugging where you'd actually want it)Drop the override entirely. Vite's default (
false) now applies in every mode; consumers opt in via their ownbuild.sourcemapconfig when they want sourcemaps (e.g. uploaded to Sentry).Tests updated:
vite-plugin-ruby/tests/index.spec.ts— assertsourcemapis no longer setvite-plugin-rails/tests/build.spec.ts— drop.mapentries from expected file listexamples/rails: gate engine alias on env varThe example used a TypeScript non-null assertion on
process.env.ADMINISTRATOR_ASSETS_PATH, which is unset at build time when no Rails engine is wired up — leaving[undefined]inserver.fs.allowand an alias resolving to"undefined/...". Vite ≤7 silently tolerated this; Vite 8 strictly path-resolvesserver.fs.allowand crashes.Make both the alias and the
fs.allowentry conditional on the env var actually being present.vite-plugin-ruby:returnafterres.end()in dev/index.html404 fallbackWithout the explicit
return, control falls through tonext()after the response has already been ended, allowing downstream middleware to write to a closed response.vite_ruby: guarddev_server_running?cache with aMutexThe prior implementation read
@runningand wrote@running_checked_atwithout synchronization, so a cold concurrent call from a multi-threaded server (e.g. Puma) could read@runningafter it was set but before@running_checked_atwas, and the next call'sTime.now - @running_checked_atcould raiseNoMethodErroronnil.Wrap the check-or-refresh in
@running_mutex.synchronizeso the cache read and write are atomic.Test plan
pnpm -C vite-plugin-ruby test --runpassespnpm -C vite-plugin-rails test --runpassesexamples/railsvite buildsucceeds with and withoutADMINISTRATOR_ASSETS_PATHset