Skip to content

Conversation

@HunterLarco
Copy link
Contributor

@HunterLarco HunterLarco commented Sep 12, 2025

Description

Fix alias resolution being incorrectly skipped for URL-like patterns in dev server.

Problem

When an alias pattern resembles a URL (e.g., { find: '//', replace: '...' }), the dev server's import analysis plugin incorrectly treats imports like //foo as external URLs and skips alias resolution (codepointer). This causes:

  1. Inconsistency with build: vite build correctly applies these aliases while dev server doesn't
  2. Broken aliases: Any alias matching URL patterns (scheme-relative, file://, etc.) fails in dev mode

Solution

Check if an import matches an alias before skipping it as an external URL.

Testing

Added test case in playground/alias/ that:

  • Defines an alias with URL-like pattern (// prefix)
  • Verifies it resolves correctly in dev server
  • Test passes with fix, fails without it

Risks

None. Projects with URL-pattern aliases are already broken in dev mode, this fixes them without impacting other flows.

@HunterLarco HunterLarco changed the title allow aliases which match URL patterns [bugfix] allow devserver aliases which match URL patterns Sep 12, 2025
@HunterLarco HunterLarco changed the title [bugfix] allow devserver aliases which match URL patterns fix: allow devserver aliases which match URL patterns Sep 12, 2025
@HunterLarco HunterLarco changed the title fix: allow devserver aliases which match URL patterns fix(vite): allow devserver aliases which match URL patterns Sep 12, 2025
@HunterLarco HunterLarco marked this pull request as ready for review September 13, 2025 01:38
Copy link
Contributor

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

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

Makes sense to me. The intent is similar to the one done for ssr external just below by #15602

// skip ssr externals and builtins
if (ssr && !matchAlias(specifier)) {

@HunterLarco
Copy link
Contributor Author

Checking in if there's anything I can do to help this land :)

@hi-ogawa hi-ogawa requested a review from sapphi-red September 24, 2025 00:25
@sapphi-red sapphi-red changed the title fix(vite): allow devserver aliases which match URL patterns fix(dev): allow aliases starting with // Oct 6, 2025
@sapphi-red sapphi-red added feat: dev dev server p2-edge-case Bug, but has workaround or limited in scope (priority) labels Oct 6, 2025
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

I guess we should remove this if block completely. But I think it's better to keep it for now.

@sapphi-red

This comment was marked as outdated.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 6, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20760

commit: 17fe255

@sapphi-red

This comment was marked as outdated.

@vite-ecosystem-ci

This comment was marked as outdated.

@sapphi-red

This comment was marked as outdated.

@vite-ecosystem-ci

This comment was marked as outdated.

@sapphi-red
Copy link
Member

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

@sapphi-red sapphi-red merged commit b95fa2a into vitejs:main Oct 6, 2025
22 of 27 checks passed
@HunterLarco HunterLarco deleted the hunter/fix-double-slash branch October 7, 2025 16:32
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Oct 15, 2025
| datasource | package | from  | to     |
| ---------- | ------- | ----- | ------ |
| npm        | vite    | 7.1.9 | 7.1.10 |


## [v7.1.10](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-7110-2025-10-14-small)

##### Bug Fixes

- **css:** avoid duplicate style for server rendered stylesheet link and client inline style during dev ([#20767](vitejs/vite#20767)) ([3a92bc7](vitejs/vite@3a92bc7))
- **css:** respect emitAssets when cssCodeSplit=false ([#20883](vitejs/vite#20883)) ([d3e7eee](vitejs/vite@d3e7eee))
- **deps:** update all non-major dependencies ([879de86](vitejs/vite@879de86))
- **deps:** update all non-major dependencies ([#20894](vitejs/vite#20894)) ([3213f90](vitejs/vite@3213f90))
- **dev:** allow aliases starting with `//` ([#20760](vitejs/vite#20760)) ([b95fa2a](vitejs/vite@b95fa2a))
- **dev:** remove timestamp query consistently ([#20887](vitejs/vite#20887)) ([6537d15](vitejs/vite@6537d15))
- **esbuild:** inject esbuild helpers correctly for esbuild 0.25.9+ ([#20906](vitejs/vite#20906)) ([446eb38](vitejs/vite@446eb38))
- normalize path before calling `fileToBuiltUrl` ([#20898](vitejs/vite#20898)) ([73b6d24](vitejs/vite@73b6d24))
- preserve original sourcemap file field when combining sourcemaps ([#20926](vitejs/vite#20926)) ([c714776](vitejs/vite@c714776))

##### Documentation

- correct `WebSocket` spelling ([#20890](vitejs/vite#20890)) ([29e98dc](vitejs/vite@29e98dc))

##### Miscellaneous Chores

- **deps:** update rolldown-related dependencies ([#20923](vitejs/vite#20923)) ([a5e3b06](vitejs/vite@a5e3b06))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: dev dev server p2-edge-case Bug, but has workaround or limited in scope (priority) trigger: preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants