How to add a class to category tr to optionally apply CSS

It might be easier to just target the data-category-id attribute instead of trying to add a class to the <tr>.

If you need to add styles to the tr without the data-category-id, you might have some luck looking into how the Category Icons theme component changes the category links render (which affects everywhere). Something along the lines of adding the class/attribute to a child element and letting the style come up with some CSS (i.e. tr:has(> .some-class)).