All cherry picks from the master branch.
@alanc @emersion @webi123 @ofourdan please shout if you think your fixes here aren't suitable for 1.20.
/cc @lyudess