refactor: remove HmrUrl concept - #23172
Conversation
Co-authored-by: c4605 <bolasblack@gmail.com>
651aef4 to
4aeb91e
Compare
3d6e4b0 to
5399f52
Compare
| isWithinCircularImport, | ||
| }) { | ||
| const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`) | ||
| const browserPath = wrapIdIfNeeded(acceptedPathWithoutQuery) |
There was a problem hiding this comment.
acceptedPath is now "moduleUrl" so wrapId is needed to convert to "browserUrl".
| // runner always caches modules by their full path without /@id/ prefix | ||
| update.acceptedPath = unwrapId(update.acceptedPath) | ||
| update.path = unwrapId(update.path) |
There was a problem hiding this comment.
HmrClient received "moduleUrl" (Url without /@id/). acceptedPath and path is now "moduleUrl" (was "HmrUrl") so unwrapId is no longer needed.
| // make sure to unwrap and normalize away base | ||
| const hmrUrl = unwrapId(stripBase(url, base)) | ||
| const isLocalImport = !isExternalUrl(hmrUrl) && !isDataUrl(hmrUrl) | ||
| const moduleUrl = unwrapId(stripBase(url, base)) |
There was a problem hiding this comment.
A simple rename here. This is/was a "moduleUrl" because unwrapId is called.
| `import { createHotContext as __vite__createHotContext } from "${clientPublicPath}";` + | ||
| `import.meta.hot = __vite__createHotContext(${JSON.stringify( | ||
| normalizeHmrUrl(importerModule.url), | ||
| importerModule.url, |
There was a problem hiding this comment.
HotContext now receives "moduleUrl" similarly to acceptedPath and path.
| const hmrAccept = normalizeHmrUrl(normalized) | ||
| str().overwrite(start, end, JSON.stringify(hmrAccept), { |
There was a problem hiding this comment.
The acceptPath of import.meta.hot.accept(acceptPath) now receives "moduleUrl", similarly to path and acceptPath. This is not a breaking change because this acceptPath argument is always rewritten by this import-analysis plugin.
| ({ acceptedVia }) => | ||
| normalizeHmrUrl(acceptedVia.url) === firstInvalidatedBy, |
There was a problem hiding this comment.
firstInvalidatedBy was "HmrUrl" (as it was sent from the client), but now it's "ModuleUrl".
| path: normalizeHmrUrl(boundary.url), | ||
| acceptedPath: normalizeHmrUrl(acceptedVia.url), | ||
| path: boundary.url, | ||
| acceptedPath: acceptedVia.url, |
There was a problem hiding this comment.
path and acceptedPath is now "moduleUrl" instead of "HmrUrl".
| return urls.size > 0 | ||
| } | ||
|
|
||
| export function normalizeHmrUrl(url: string): string { |
There was a problem hiding this comment.
This conversion happens on the client side when importing a module (i.e. when "moduleUrl" is converted to "browserUrl").
| // moduleUrl must be derived the same way as importAnalysis | ||
| const moduleUrl = unwrapId( |
There was a problem hiding this comment.
This is a simple rename. This is/was a "moduleUrl" because unwrapId is called.
There was a problem hiding this comment.
As noted in this file and hmrPayload.d.ts, technically these fields will have slightly different behavior. But I assume this won't be a huge problem.
|
/ecosystem-ci run |
@vitejs/plugin-legacy
vite
commit: |
|
📝 Ran ecosystem CI on
✅ vite-plugin-react, module-federation, marko, analogjs, vite-plugin-pwa, vite-plugin-svelte, unocss, laravel, vite-setup-catalogue, vite-plugin-cloudflare, vitepress, vite-plugin-vue, vuepress, vite-plugin-rsc, vite-environment-examples, quasar, waku, vike, nuxt |
|
^ storybook failure seems unrelated |
bluwy
left a comment
There was a problem hiding this comment.
I like this refactor. Let's try this in the next minor and hope it doesn't break many people.
This PR removes the "HmrUrl" concept.
There were three "Url" concept in Vite:
\0\0virtual:foo\0/base/@id/__x00__virtual:foo?t=123\0/@id/__x00__virtual:fooIt is confusing to have three kinds of representation. I think the HmrUrl is not needed as well.
Stack created with GitHub Stacks CLI • Give Feedback 💬