Skip to content

fix: pending requests after module invalidation#7283

Merged
patak-cat merged 2 commits intomainfrom
fix/pending-requests-after-invalidation
Mar 13, 2022
Merged

fix: pending requests after module invalidation#7283
patak-cat merged 2 commits intomainfrom
fix/pending-requests-after-invalidation

Conversation

@patak-cat
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-cat patak-cat requested review from antfu and bluwy March 11, 2022 20:27
@patak-cat patak-cat marked this pull request as draft March 11, 2022 20:31
@patak-cat patak-cat marked this pull request as ready for review March 11, 2022 20:35
@patak-cat patak-cat merged commit a1044d7 into main Mar 13, 2022
@patak-cat patak-cat 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.

2 participants