Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class NxVersionUtil(private val project: Project, private val cs: CoroutineScope
return if (ApplicationManager.getApplication().isDispatchThread) {
nxVersion
} else {
Comment on lines 49 to 51

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Inconsistent behavior between dispatch and non-dispatch threads. When nxVersion is null on the dispatch thread, it returns null immediately without trying fallback methods. However, on non-dispatch threads, it attempts fallbacks via tryGetNxVersionFromNodeModules() and tryGetNxVersionFromPackageJson(). This creates unpredictable behavior where the same call returns different results depending on which thread it's called from.

If the dispatch thread case also needs to try fallbacks when nxVersion is null, it should wrap the fallback logic in ApplicationManager.getApplication().runReadAction<NxVersion?> or use invokeLater to avoid blocking the EDT:

return if (ApplicationManager.getApplication().isDispatchThread) {
    nxVersion ?: ApplicationManager.getApplication().runReadAction<NxVersion?> {
        tryGetNxVersionFromNodeModules() ?: tryGetNxVersionFromPackageJson()
    }
} else {
    nxVersion ?: ApplicationManager.getApplication().runReadAction<NxVersion?> {
        tryGetNxVersionFromNodeModules() ?: tryGetNxVersionFromPackageJson()
    }
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

nxVersion ?: tryGetNxVersionFromNodeModules() ?: tryGetNxVersionFromPackageJson()
nxVersion
?: ApplicationManager.getApplication().runReadAction<NxVersion?> {
tryGetNxVersionFromNodeModules() ?: tryGetNxVersionFromPackageJson()
}
}
}

Expand Down
Loading