Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If an action tries to unmount a parcel while its already unmounting, the parent application gets set to SKIP_BECAUSE_BROKEN #1184

Open
bkfarnsworth opened this issue Dec 21, 2023 · 3 comments · May be fixed by #1189

Comments

@bkfarnsworth
Copy link

Hi single-spa team, I'm happy to work on a PR for this issue if it is indeed a bug or an enhancement, and you can give me some pointers. Thanks!

Describe the bug or question
If some action tries to unmount parcels that are already in the UNMOUNTING state, the parent application will be set to SKIP_BECAUSE_BROKEN because the parcels can only be unmounted if they are in the MOUNTED state. The use case we have that triggers this is this: We mount some parcel components inside of a popover. When clicking submit in the popover, the popover unmounts, it sets the parcels to the UNMOUNTING state, but then in the same frame we also change the url to navigate somewhere, so it tries again to unmount the parcels again, and it fails. We can work around this by putting the url change in a setTimeout, but we are going to be using these parcels in a lot of similar places, so we'd like to find a scalable solution.

I've recorded a screen recording that walks through the issue in more detail, and shows lines of single-spa code that I think we could change to fix the issue: https://drive.google.com/file/d/1i-777GteMgk7aT2IeUcjy4-J682iDA_p/view?usp=sharing

Expected behavior
If a parcel is already unmounting, and another unmount request comes in, it latches on to the original unmount request. Maybe we should also consider other states, like UPDATING ie single-spa can just wait for the component to be back in the MOUNTED state, and then it will unmount.

@joeldenning
Copy link
Member

I don't think a change to single-spa is necessary here, since parcel.getStatus() can be called to check whether the parcel is ready to unmount:

if (parcel.getStatus() === "MOUNTED") {
  parcel.unmount();
}

I'm open to discussing changing the related internal single-spa logic, but don't see why it's necessary

@bkfarnsworth
Copy link
Author

bkfarnsworth commented Jan 3, 2024

@joeldenning I'm using single-spa-react, so I don't ever call parcel.unmount on my side manually. It gets unmounted because the parent react component gets unmounted, and then tries to unmount again in the same tick of the event loop when the route changes. I've put a bandaid in for now where I get a reference to the parcel and I poll the status until it is in the MOUNTED state. But its not a scalable fix - we will share many components cross-MFE, and we will run into this issue again and again. It seems like parcel should be able to handle if a call to unmount comes in while it is in the UNMOUNTING state

@BeastlyUnsold BeastlyUnsold linked a pull request Jan 5, 2024 that will close this issue
@MilanKovacic
Copy link
Collaborator

Hi @bkfarnsworth, sorry for the late reply. We were/are working on internal improvements. I will take a look at the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants