Backport of #8995 to 0.3

@nolta I have prepared a backport of #8995