A PR containing changes that should fix this has been started at https://github.com/xwiki/xwiki-platform/pull/4265