Attached patch fixes the problem for me. It applies cleanly to both emacs-29 and master.