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: do not append version query param when scanning for dependencies #11961

Merged

Conversation

shYkiSto
Copy link
Contributor

@shYkiSto shYkiSto commented Feb 7, 2023

Description

Ensure dependency scanner does not skip over bare imports for which there's an alias to an absolute path configured in the vite.config.js. Previously this would trigger expensive "full reloads", and invalidate all of the modules in the module graph when a missing dependency is found while "crawling" (see optimizer.ts). This does not seem to be necessary in this case, as it should be able to figure out all of the used dependencies during the initial pass.

This used to happen because a version query param was appended to the resolved path, when resolving aliased module id (an absolute path, see resolve.ts). In which case the dependency optimizer would skip over such dependencies as it would not match the regex that specifically checks that the path ends with a file extension (see isOptimizable() @ utils.ts).

Additional context

I've added a missing setup to handle this test scenario in the optimize-deps playground, but could not figure out a reliable way to check for unnecessary full reloads in tests.

FWIW, the existing test suite started to fail because of unexpected reloads, and to fix it I had to add the index.html to the entries, so all of the dependencies are pre-bundled for the first page load.


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.

@shYkiSto shYkiSto force-pushed the fix-deps-scanner-absolute-path-alias branch from 2841137 to 1a7b09e Compare February 7, 2023 01:34
@shYkiSto shYkiSto force-pushed the fix-deps-scanner-absolute-path-alias branch from 1a7b09e to 5196c5c Compare February 7, 2023 01:36
@bluwy bluwy added the feat: deps optimizer Esbuild Dependencies Optimization label Feb 16, 2023
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The tests are great too 👍 Thanks for the thorough explanation of what's going on, even if it's a one-line fix!

@bluwy bluwy added the p3-minor-bug An edge case that only affects very specific usage (priority) label Feb 19, 2023
@patak-dev patak-dev merged commit 575bcf6 into vitejs:main Feb 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: deps optimizer Esbuild Dependencies Optimization 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.

3 participants