Thanks to @m5o for the implementation idea!
Fixes #27395 (closed), closes #27491
Backported and adapted for v4-dev from #27632
Thanks to @m5o for the implementation idea!
Fixes #27395 (closed), closes #27491
Backported and adapted for v4-dev from #27632