Skip to content

fix: dev server intercepts Vite URLs when basePath is configured#3730

Merged
bartlomieju merged 3 commits into
mainfrom
fix/basepath-client-entry-404
Mar 29, 2026
Merged

fix: dev server intercepts Vite URLs when basePath is configured#3730
bartlomieju merged 3 commits into
mainfrom
fix/basepath-client-entry-404

Conversation

@bartlomieju

Copy link
Copy Markdown
Contributor

Summary

When base: "/ui/" is set in vite.config.ts, the Fresh dev server middleware intercepted Vite's virtual module URLs (like /ui/@id/fresh:client-entry) instead of passing them to Vite's middleware, causing 404s for client-entry JS and island code.

Root cause

The IGNORE_URLS regex was hardcoded as /^\/(@(vite|fs|id)|\.vite)\//, which only matches URLs starting with /@id/, /@vite/, etc. When Vite's base is set to /ui/, virtual module URLs become /ui/@id/... which didn't match.

Fix

Build the regex dynamically from server.config.base, matching both /@id/... and /ui/@id/...:

const base = server.config.base.replace(/\/$/, "");
const IGNORE_URLS = new RegExp(`^(${base})?/(@(vite|fs|id)|\\.vite)/`);

Test plan

  • Verified /ui/@id/fresh:client-entry returns 200 (was 404)
  • Verified /ui/@vite/client returns 200 (was 404)
  • Verified /@id/... without base still works (backward compatible)

Closes #3666

🤖 Generated with Claude Code

bartlomieju and others added 3 commits March 28, 2026 11:24
When `base: "/ui/"` is set in vite.config.ts, Vite prefixes virtual
module URLs with the base path (e.g., `/ui/@id/fresh:client-entry`).
The Fresh dev server middleware's IGNORE_URLS regex only matched
`/@id/...` without the base prefix, causing it to intercept these
requests instead of passing them to Vite's middleware.

The fix builds the IGNORE_URLS regex dynamically from the configured
base path, matching both `/@id/...` and `/ui/@id/...`.

Closes #3666

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a test fixture with `base: "/ui/"` and a test verifying that
Vite's `/@vite/client` URL is accessible when a base path is configured.
Without the fix, Fresh's dev server middleware intercepted these URLs
and returned 404.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bartlomieju bartlomieju enabled auto-merge (squash) March 29, 2026 19:37
@bartlomieju bartlomieju merged commit e0ee53d into main Mar 29, 2026
8 of 9 checks passed
@bartlomieju bartlomieju deleted the fix/basepath-client-entry-404 branch March 29, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClientEntry not found issues when changing base path

1 participant