-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
fix: consider URLs with any protocol to be external #17369
Conversation
Run & review this pull request in StackBlitz Codeflow. |
yeah, cos an external url can also be a local file in electron right, so if it's hardcoded for http(s) it would break on 'file:///', right? |
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, histoire, ladle, laravel, marko, previewjs, quasar, qwik, rakkas, remix, sveltekit, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-setup-catalogue, vitepress |
/ecosystem-ci run vite-plugin-vue |
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.
I don't see a reason to limit a external URL to only be http
. Users could be using ipfs://
for example. The original function was added as part of bigger features so there is no history about having to restrict it: fbf7ab4#diff-071a32aedd2ea59472ebb69fb456e818b103d1a332da632e12c2d54395938ad1R10
I think One thing to point out is that IIUC this will make non-
virtual: seems to be used in many places (GitHub search result).
I think we can fix this by either
|
Good call with Could you expand on the |
My bad, forgot that the regex includes |
Just noticed that |
/ecosystem-ci run |
This comment was marked as outdated.
This comment was marked as outdated.
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, histoire, ladle, laravel, marko, previewjs, quasar, rakkas, remix, sveltekit, unocss, vike, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress |
The vite-plugin-pwa looks like a fluke due to a failed sharp install. @bluwy, the Astro fail seems legit. It seems there is a test for |
I don't know if this would fix it, but Astro has a |
It seems that Astro decided to make |
For me (and also mentioned in the meeting), I think it would be nice if Vite can support it in the future, and this is also more of a stop point. |
If we want to do this, for now maybe we shouldn't change how |
I think either way works for me, but since this will be merged in the next major, it shouldn't have a big impact in practice. |
We did it this way because we use URLs almost exclusively and it was easier just to pass the URL as a module specifier rather than convert it to a path. I'm always unsure if paths needed to be converted to forward slashes, or if they can start with I don't think I understand the logic of why |
In our meeting notes, we decided to not externalize |
I think we should merge #18422 before this PR in that case. I guess it might be confusing when debugging later on finding that plugins handling fileURLs not working for some commits. |
if ( | ||
(isExternalUrl(specifier) && !specifier.startsWith('file://')) || | ||
isDataUrl(specifier) | ||
) { |
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.
Added this !specifier.startsWith('file://')
to make file URLs work.
/ecosystem-ci run |
This comment was marked as outdated.
This comment was marked as outdated.
📝 Ran ecosystem CI on
✅ analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, storybook, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress |
Description
Right now, when building, vite checks if the
base
provided is an external URL by checking if it starts withhttps://
orhttp://
. This doesn't have to be the case. When working with electron, for example, one can create a custom protocol, then load the page with it. Right now setting thebase
tosandbox://
causes a broken app in electron. This PR fixes it.fixes #13540