-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent query-params added by vite to be passed to core logic #1846
Conversation
55def40
to
7b2ea00
Compare
packages/vite/src/request.ts
Outdated
let cleanSource = cleanUrlQueryParams(source); | ||
let queryParams = getUrlQueryParams(source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ef4 I tried to replace these regexp-based methods with a URL object, but it caused trouble because the source
can be a relative path. Here are examples of specifiers I get with both methods:
URL : /app,
Regexp: ../app,
URL : /-embroider-implicit-modules.js,
Regexp: ./-embroider-implicit-modules.js,
URL : /packages/macros/src/addon/es-compat2,
Regexp: ../../../../../../packages/macros/src/addon/es-compat2,
…> when instantiating a new RollupModuleRequest from an import to resolve
…> when asking for a virtual content
…er URL over Regexp to clean-up when possible
packages/vite/src/resolver.ts
Outdated
let { src, watches } = virtualContent( | ||
cleanUrlQueryParams(id.slice(virtualPrefix.length)), | ||
resolverLoader.resolver | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only parameter I have on load
is the id
, which corresponds - I guess - to a result.id
as it contains the query params. I don't see any obvious way to avoid cleaning again the query params before passing to virtualContent
.
…rce ones (re-add them in the resolution)
7b2ea00
to
f580815
Compare
Context
PR #1805 highlighted how Vite sometimes adds internal query parameters to requests. For instance, if you include a CSS file directly in
index.html
with alink
tag pointing to a stylesheet, then Vite will internally add the query parameter?direct
to the request so it knows it has to return the stylesheet as is without wrapping it in some hot-reload-related JS. This is just one example of the sort of things Vite can do for its own reason.The problem is that Embroider doesn't expect this kind of query params to exist, for instance when dealing with virtual files, and we can't let the core part of Embroider know about that: it is bundler-agnostic, it should behave the same way if you use Vite, or Webpack, or whatever.
Problem to solve
Everything that has to do with Vite query params should stay in
packages/vite/src
and from this point, we need to make sure that:packages/core/src
functions that are bundler-agnostic.How to test
isDirect
in Vite resolver, and thevendor.css
should still be generated correctly.