Scripts in nested components

I can’t find answer, sorry if I’m blind. It looks like very basic example when livewire should work but it won’t. Please tell me is it possible to run scripts in nested components which are initialized conditionally?

@if($type)
<livewire:foo>
@else
<livewire:bar>
@endif
 
* foo.blade.php
<div>
<script> alert('foo is run'); </script>
</div>

* bar.blade.php
<div>
<script> alert('bar is run'); </script>
</div>