The behavior is happening because of the way the aura framework stores the component id. For example when the modal is first open, the lightning component is registered to a map, at this point when we call component.find() we get an single object back, when we close and reopen the modal, the component is registered again but because a component with the same aura id already exists in the map, it is converted to a array and this array is returned to the user when they call component.find().
Always validate the return type of the method component.find('auraId') i.e. and proceed with business logic
Example:
const cmps = component.find("auraId’");
if (!cmps) return;
if ($A.util.isArray(cmps)) {
cmps.forEach(cmp => {
// business logic
})
} else {
// business logic
}
In Nutshell, update the controller logic to handle both a single component reference and an array result from component.find. Use $A.util.isArray on the result, iterate from the end of the array, select the instance that is valid and rendered, and only then access value.
Here's the reference documented Aura behaviour for component.find and consider planning migration of complex dynamic workflows from Aura to Lightning Web Components.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_jsapi_component_find.htm
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_find_by_id.htm
005388612

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.