-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
feat: read sec-fetch-dest
header to detect JS in transform
#9981
Conversation
The problem is that known sources of JS are used in other places, and not only in this condition. I think we should try to resurrect @dominikg's #3828 so @haikyuu can add |
Hmm, @dominikg's PR was in response to #2829, which discusses various issues with dependency scanning and bundling for non-Vue/Svelte/Astro SFCs. That looks like a different beast to me, and also requires changes for the html detection regex and the SFC script extraction logic as described in the first comment there.
From a quick search through the Vite source, Overview of
|
Hmm, after thinking this through, running the |
If I understand you correctly, you want us to start marking every known JS source with |
No, I just want to append
to this:
to make sure that these to behave the same way: <script type="module" src="./entry.myjsdialect"></script>
<!-- and -->
<script type="module">import "./entry.myjsdialect"</script> Currently, the first variant breaks because the entry file will not be transformed by plugins, but the second variant works. That's inconsistent behavior imo. So the change would be to run the src attr of a |
This is a stretch of the word import, but it makes sense to me as a temporal patch. I think we can do it and work to expose a configuration option or change the scheme in other PRs |
Cool, gonna update the PR later! 👍 And yeah, thinking of an entry src as an import first sounded strange to me too. But it kind of makes sense when you consider that it should be equivalent to an actual import statement in an inline module script — and MDN calls it an import, too:
|
Re About appending So I think there's three ways here:
While writing this comment, I came up with the third one and I feel it's the best approach for now. |
Agreed, browser support is not quite there yet. But fwiw, the
But yeah, |
I will test this tomorrow and see if it works. |
That must be an error on your side, can't reproduce. However it does indeed not work – if (importQueryExists(id)) {
if (id.endsWith('.imba')) addImportQuery() // ← never reached! :(
transform()
} |
I guess we can add imba to the hardcoded list and work on a proper mechanism to allow plugin developers to declare their extensions |
That's a good point, I totally forgot that... configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url.endsWith('.imba')) {
req.url += '?import'
res.setHeader('Content-Type', 'application/javascript')
}
next()
})
}, |
@sapphi-red That's great. That actually works, thank you :) https://stackblitz.com/edit/vitejs-vite-gmkyeg?file=vite.config.js I'll now make a new version of the plugin. Should we document this in the plugins section? or do you think it's worth adding as an option to the plugin api? |
After some testing, I found a little tweak to @sapphi-red's solution in order to support query params that are added sometimes:
|
But that seems to break other things. I have a couple of failing tests now that are complaining about this
https://github.com/vitejs/vite/blob/main/packages/vite/src/node/server/moduleGraph.ts#L144 |
@haikyuu you may want to use a utility like vite/packages/vite/src/node/utils.ts Line 307 in 9f8d79b
Note: Maybe we could expose |
Safari 16.4 Beta added support for Fetch Metadata Request Headers. So in a year, I guess we can start using |
is there any workaround in the meantime? could this be otherwise merged? there's another solution in: #3828 which could be good too... |
Again cautiously noting that Vite does already use |
We discussed in the last meeting whether we can merge this in Vite 5. It's been only half a year since Safari started supporting Re the fact Vite already uses |
i believe we should do even more. just exposing this util and expecting most framework plugins to call configureServer and bring the same update middleware is still duplicating that code over a lot of plugins. Setting up custom extensions is a common need so it should be as easy as defining an array of extensions that transform to js. |
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, histoire, ladle, laravel, nuxt, quasar, qwik, rakkas, storybook, unocss, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress |
sec-fetch-dest
header to detect JS in transform
Description
fix #9963
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).