Skip to content

Conversation

wesdimiceli
Copy link

Description

I was noticing that certain modules weren't updating when saving a change to their dependencies, and traced it back to this recent addition:
https://github.com/vitejs/vite/blob/v2/packages/vite/src/node/plugins/importAnalysis.ts#L676-L679

What's happening is some modules are given a browser-safe URL with the /@id/ prefix before they're added to the module graph. Then the above code strips the prefix and the imports are sent back through the transform pipeline, which adds duplicate modules without the prefix. This has the effect of creating a discontinuous module graph.

I would expect it to look like this:

entry.js -> /@id/__x00__virtual:my-module -> dependency.js

But instead the graph looks like this:

entry.js -> /@id/__x00__virtual:my-module
virtual:my-module -> dependency.js

Thus any changes made to dependency.js don't properly trickle down when purging the module cache and I must restart the server to see the changes.

I've been running this fix in an internal project for a few weeks via a yarn patch. Wanted to contribute the fix and a failing test.

Additional context

The fix essentially moves the /@id/ unwrapping to a more-central location alongside a tiny change to re-use module IDs if they already exist in the graph.


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 Commit 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.

@netlify
Copy link

netlify bot commented Jun 27, 2022

Deploy Preview for vite-docs-v2 ready!

Name Link
🔨 Latest commit a9d6667
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-v2/deploys/62b932cfd814880009ac32bb
😎 Deploy Preview https://deploy-preview-8807--vite-docs-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant