Skip to content
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: use consistent virtual module ID in module graph #13073

Merged

Conversation

fi3ework
Copy link
Member

@fi3ework fi3ework commented May 2, 2023

Description

When investigating #12912, I found that when accepting virtual:my-plugin:foo like below

import.meta.hot.accept(['virtual:my-plugin:foo'], { /** code */ })

This will lead to adding a /src/virtual:my-plugin:foo generated by the following code to the module graph, however, IIUC, virtual module's URL should not be calculated with the importer.

const [normalized] = await moduleGraph.resolveUrl(
toAbsoluteUrl(url),
ssr,
)


In this PR, the test case is modified to only update the virtual module as below.

import.meta.hot.accept(
    ['virtual:file', '/@id/__x00__virtual:file'],

To fix #12912 ideally, we shall only use 'virtual:file' but the HMR dilemma now is like this:

  • acceptedPath send to the client is "/@id/__x00__virtual:file"
  • the acceptedPath defined in main.js must include "/@id/__x00__virtual:file" to receive the update.

I'm not sure what's the best way to fix this, but I think it's straightforward to avoid assembling URL for virtual file with the importer in this PR. Looking forward to some feedback 🙌.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented May 2, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev
Copy link
Member

/ecosystem-ci run

@patak-dev patak-dev added this to the 4.4 milestone May 3, 2023
@vite-ecosystem-ci
Copy link

vite-ecosystem-ci bot commented May 3, 2023

📝 Ran ecosystem CI: Open

suite result
astro ✅ success
histoire ✅ success
iles ✅ success
ladle ✅ success
laravel ✅ success
marko ✅ success
nuxt ❌ failure
previewjs ✅ success
qwik ✅ success
rakkas ✅ success
sveltekit ✅ success
vite-plugin-ssr ✅ success
vite-plugin-react ✅ success
vite-plugin-react-pages ✅ success
vite-plugin-react-swc ✅ success
vite-plugin-svelte ✅ success
vite-plugin-vue ✅ success
vite-setup-catalogue ✅ success
vitepress ✅ success
vitest ✅ success
windicss ✅ success

@patak-dev patak-dev added feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority) labels May 3, 2023
@patak-dev
Copy link
Member

Ecosystem CI looks good. The Nuxt failure is in main too 👍🏼

@fi3ework fi3ework force-pushed the fix-virtual-module-id-in-module-graph branch from 7cc1d96 to 173a02f Compare May 4, 2023 14:26
@bluwy
Copy link
Member

bluwy commented May 8, 2023

  • acceptedPath send to the client is "/@id/__x00__virtual:file"

Maybe we can unwrap the id before we send it to the client? 🤔 Looks like I was the one who messed that up at #10324, I didn't add a test for that, and it was to address #10313. Maybe we should wrap the id in the client instead?

@patak-dev
Copy link
Member

@bluwy could you explain why that would be better? I think it is more clear to me if the client already receives /@id/__x00__virtual:file", no? From the client POV, always getting valid URLs from the Vite dev server is easier to explain IMO

@bluwy
Copy link
Member

bluwy commented May 16, 2023

Hmm yeah after refreshing myself of what values the acceptedPath is usually gets passed with, seems like it's always URLs, so makes sense to continuing wrapping it, but unwrapping it later in the client again.

Also I tested with /@fs/ and it looks like the /@fs/ path is sent to the client too (not sure if HMR is fine with it though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fails to hmr accept virtual modules
3 participants