I think there have been a couple of fixes added for this issue, so you may be able to remove your custom code after an update. ![]()
https://github.com/discourse/discourse/commit/ab217d8ae0b06ae4a9ce94aa2ff200aa84789189
https://github.com/discourse/discourse/commit/c937b6dd36ace3c1fb005eba2c6fee83d5b1e073