Fixes #30097, regression from #29894. (cherry picked from commit 30a561ce569fcb1dfc12edf658104a126281494d)