Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 24, 2025

  • Fixed issue in clientInjections.ts by using cleanUrl(id)
  • Added test case that imports /@vite/env?foo to verify the fix
  • Moved test to dev-only plugin per feedback
  • Built and linted successfully
  • CodeQL security check passed

Issue Summary

The issue (#20997) is in /packages/vite/src/node/plugins/clientInjections.ts. When query parameters are appended to the env entry URL (e.g., /@vite/env?token=xxx), the strict equality check fails, causing __DEFINES__ to not be replaced, resulting in a ReferenceError.

Solution

  • Import cleanUrl from ../../shared/utils
  • Use cleanUrl(id) to strip query parameters before comparing with normalizedClientEntry and normalizedEnvEntry
  • Created a dev-only plugin in playground/define/vite.config.js that adds the test import during transformation
  • The plugin uses apply: 'serve' to ensure it only runs in development mode

Testing

The test imports /@vite/env?foo via a plugin that only applies during dev mode, ensuring the fix works correctly without affecting build behavior.

Original prompt

Fix #20997 by using cleanUrl(id). Add a test to https://github.com/vitejs/vite/tree/main/playground/define that imports /@/vite/env?foo and ensures that the error does not happen.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Import cleanUrl from shared/utils in clientInjections.ts
- Use cleanUrl(id) before comparing with normalizedClientEntry and normalizedEnvEntry
- Add test case that imports /@vite/env?foo to verify the fix
- Ensures __DEFINES__ is properly replaced even when query parameters are present

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with cleanUrl function in error handling fix: handle query parameters in client and env entry URLs Oct 24, 2025
Copilot AI requested a review from sapphi-red October 24, 2025 08:36
@sapphi-red
Copy link
Member

@copilot add the import by a plugin. only apply that plugin when commamd is dev.

Move the test import from inline code to a vite plugin that only
applies during dev mode. This ensures the test doesn't run during
build, making it more robust and following best practices.

Addresses feedback from @sapphi-red

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 24, 2025

@copilot add the import by a plugin. only apply that plugin when commamd is dev.

Done. The test import is now added by a plugin with apply: 'serve' to ensure it only runs in dev mode. See commit ffc9a54.

Copilot finished work on behalf of sapphi-red October 24, 2025 09:40
@sapphi-red sapphi-red marked this pull request as ready for review October 26, 2025 11:09
@sapphi-red sapphi-red changed the title fix: handle query parameters in client and env entry URLs fix: handle query parameters for /@vite/* modules Oct 26, 2025
@sapphi-red sapphi-red added p2-edge-case Bug, but has workaround or limited in scope (priority) feat: dev dev server labels Oct 26, 2025
@sapphi-red sapphi-red merged commit 6843a6a into main Oct 27, 2025
21 checks passed
@sapphi-red sapphi-red deleted the copilot/fix-clean-url-usage branch October 27, 2025 01:21
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uncaught ReferenceError: __DEFINES__ is not defined at env.ts:17:17

3 participants