This is the same fix as in rBde35a90f9f56d3ff3ac80c13bf1ae296853ba877 but for the blender-v3.0-release branch.