NB. This is the second part of the implementation of #17594 (closed). The first part is at !6313 (closed).