How do I trigger scripts when layout of ReactiveHTML component changes?

I’m trying to review and finalize a PDBMolstar component contributed by @Jhsmit to panel-chemistry. But I can see the component does not resize when I change layout parameters like width, height and sizing_mode.

So my question is really. How do get the PDBMolstar component to resize when the ReactiveHTML component has resized?

I can see that the molstar component resizes if I run window.dispatchEvent(new Event('resize'));. So how do I trigger this script.

I looking for something like that works. The width script is not run when change the width.

import panel as pn
import param

pn.extension()

class PDBeMolStar(pn.reactive.ReactiveHTML):
    _template = "<div id='component' style='height:100%;width:100%;background:gray;'>Count: ${resizes}</div>"

    resizes = param.Integer()

    _scripts = {
        "width": "console.log('width');window.dispatchEvent(new Event('resize'));data.resizes+=1",
    }

component = PDBeMolStar(width=500, height=500, sizing_mode="fixed")
pn.Column(component, component.param.width).servable()