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: prevent race condition between transformRequest and optimizeDeps (fix #6508) #6543

Closed

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Jan 17, 2022

Description

Fixes #6508

The idea behind this PR is to prevent further transformations of a module in the case the deps optimizer has been run after reading the module's source code but before reading the source maps. It is useless to continue transformations as running the optimizer will invalidate all the modules in the end. This should prevent the race condition described in the linked issue and fix irrelevant Failed to load source map for .vite/chunk-AJFLDE.js warnings that are caused by that race condition.

Additional context

The transformRequest function can be invoked:

  1. By making a direct HTTP request to a module. In this case, the change will cause the server to return 404 for the module if the optimizer has been run in the mentioned circumstances. The module will be transformed normally after a full reload that the optimizer will cause eventually.
  2. By the importAnalysis plugin during the pre-transformation of the module's imports. In this case, the module will be just skipped until a full reload that the optimizer will cause eventually.

What is the purpose of this pull request?

  • Bug fix

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.

@vursen vursen force-pushed the fix/prevent-transform-when-optimizing-deps branch from 5c51e44 to 92d3f7c Compare January 18, 2022 07:21
@vursen vursen marked this pull request as ready for review January 18, 2022 07:46
@vursen vursen changed the title fix: make transformRequest return null if the optimizer has been run fix: do not continue module transformation when the optimizer has been run meanwhile Jan 25, 2022
@vursen vursen changed the title fix: do not continue module transformation when the optimizer has been run meanwhile fix: stop module transformation if the optimizer has been run meanwhile Jan 25, 2022
@vursen vursen changed the title fix: stop module transformation if the optimizer has been run meanwhile fix: stop module transformation when the optimizer runs Jan 25, 2022
@vursen vursen changed the title fix: stop module transformation when the optimizer runs fix: stop module transformation when the deps optimizer runs Jan 25, 2022
@vursen vursen changed the title fix: stop module transformation when the deps optimizer runs fix: prevent race condition between transformRequest and optimizeDeps Jan 25, 2022
@vursen vursen changed the title fix: prevent race condition between transformRequest and optimizeDeps fix: prevent race condition between transformRequest and optimizeDeps (fix: #6508) Feb 2, 2022
@vursen vursen changed the title fix: prevent race condition between transformRequest and optimizeDeps (fix: #6508) fix: prevent race condition between transformRequest and optimizeDeps (fix #6508) Feb 2, 2022
@vursen vursen closed this Apr 15, 2022
@vursen vursen deleted the fix/prevent-transform-when-optimizing-deps branch April 15, 2022 14:54
@vursen
Copy link
Contributor Author

vursen commented Apr 15, 2022

Closed as the issue was already fixed in a different PR.

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.

"Failed to load source map" warnings appear because of a race condition
1 participant