How do I execute a snippet of JS at (re)paint

As a workaround for a UI problem I’m having (see https://vaadin.com/forum#!/thread/7979972) I need to execute a snippet of JS every time a specific component is redrawn (for instance when switching to a tab where the component is). The snippet of JS I have modifies the DOM (adds styles to elements) but these changes are lost when switching tabs (for exmaple). I need to figure out when the component is redrawn and then re-execute the snippet of JS.

I understand this would’ve been easy with Vaadin 6 where you possibly could override a ‘paint’ method (or something like that), but I cannot figure out how to do it with Vaadin 7. I’ve tried various DOM events and adding listeners etc on the Java side.

Any help would be greatly appreciated.

Override beforeClientResponse method.
Alternativly you could create a JavaScriptExtension for that task.

Thank you! Works like a charm.