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: pending requests after module invalidation #7283

Merged
merged 2 commits into from Mar 13, 2022

Conversation

patak-dev
Copy link
Member

Description

Continuation on the work started by #7254

When we invalidate a module, we don't cache results for in-fly requests after #7254.

We also cache pending requests so we can collapse requests for the same resource while processing. This is important due to the way Vite crawls the whole module graph eagerly even before the browser does the requests.

After invalidation, we need to also consider the case

// Request 1 for module A     (pending.timestamp)
// Invalidate module A        (module.lastInvalidationTimestamp)
// Request 2 for module A     (timestamp)
// Finish processing 1, then 2 ends up with a stale result

This PR fixes this case. This is another case that is difficult to test and reproduce, so users may have run against it without being able to send the report.

@antfu I didn't use AbortController as we need Node 15 IIUC. It could be interesting to save the promise in the Module instead of in _pendingRequests that would lead to a similar scheme like you proposed but looks like we may not always have a Module since we only create it in the module graph after a successful load (so in the middle of the processing). Maybe we could create a Module upfront and keep it in a moduleGraph._pending and only add it after load. Maybe we could do this refactoring in another PR.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@patak-dev patak-dev requested review from antfu and bluwy March 11, 2022 20:27
@patak-dev patak-dev marked this pull request as draft March 11, 2022 20:31
@patak-dev patak-dev marked this pull request as ready for review March 11, 2022 20:35
@patak-dev patak-dev merged commit a1044d7 into main Mar 13, 2022
@patak-dev patak-dev deleted the fix/pending-requests-after-invalidation branch March 13, 2022 07:01
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.

None yet

2 participants