Thanks for the reproduction steps! I fixed the bug in this PR:
https://github.com/discourse/discourse/pull/16478