Dialogs, Popups, Pickers, Notifications works with templates.
Code usually looks like this:
Clone() method creates a new instance of the dialogTemplate (or takes an instance from the cache if available) and displayed will be this instance, not the original template.
This way, you need only one template to display multiple dialogs at the same time, and also closed dialogs instances are automatically recycled.
But if you have a script outside of the dialogTemplate hierarchy and it has reference to the component inside a hierarchy, this reference will never be replaced with the new instance.
The script will be work with dialogTemplate, not with actually displayed dialog. To change this behavior, you need to move the script inside the dialog hierarchy.