Dynamically adding or removing `contain: style` does not invalidate counters. There is currently no WPT for it.
The same bug is present in Chrome fwiw.
Would this address this bug? https://bugs.webkit.org/show_bug.cgi?id=246764
*** This bug has been marked as a duplicate of bug 246764 ***