Description
This is a follow-up to #6841 (which was fixed by #6857)
This issue explains why our inspector_service
tests failed to detect the regression. Once we infer the pub root directory for a project, we cache it across subsequent loads of DevTools, and never try to re-infer it.
Explanation of current behavior:
When DevTools is opened for the first time, or after the cache has been cleared:
- No cached directories are added to the widget inspector service (code link)
- Fetching directories from the widget inspector service returns nothing (code)
- Therefore, DevTools tries to infer the pub root directory (“Directory A”) and adds it to the widget inspector service (code)
- Directory A is then cached (code)
On any subsequent loads of DevTools:
- The cached Directory A is added to the widget inspector service (code link)
- Directory A is fetched from the widget inspector service (code)
- Because Directory A was fetched, we do not try to infer the pub root directory (code)
Expected behavior
I believe the caching was added because we want to save any project directories manually added by a user in the Inspector Panel settings dialogue (code). However, I don't think we want to ever cache the inferred pub root directory.
Potential fixes
- Always inferring the app's pub root directory but do not change any of our caching logic (but this means any stale inferred pub root directories stick around in the cache)
- Always inferring the app's pub root directory and do change our caching logic to only cache pub root directories that users have manually set (but this would mean invalidating all the caches first, and then users would have to re-add any custom pub root directories that they had previously set)
If we go with potential fix #1, we should also consider removing the flutter pub root directory if we detect it in the cache, since the flutter pub root directory was being erroneously inferred (the cause of #6841) and is now cached for any apps that encountered that issue.