Merge "Refactor migrateGridIfNeeded to pass the grid states and make it easier for unit testing" into main