-
-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Problems with mounting the same parcelConfig multiple times #234
Comments
The issue here is that the Whenever we modify the Here are the things that need to be figured out:
single-spa-angular/libs/single-spa-angular/src/single-spa-angular.ts Lines 144 to 145 in a446de5
One way that we can have separate variables for each mounted instance is to do something like this: export function bootstrap(options, props) {
options.instances[props.name || props.appName] = {};
}
export function mount(options, props) {
const instance = options.instances[props.name || props.appName]
instance.bootstrappedModule = ...
}
export function unmount(options, props) {
const instance = options.instances[props.name || props.appName]
delete instance.bootstrappedModule
} |
Hi, is there a way out for this already? |
It's an outstanding bug / limitation. I'd be happy to review a pull request fixing it - my comment above provides some guidance about it |
Hi, faced same problem, as I can understand this is still issue and it's impossible to use same several parcels in one app on same page? |
With the current limitation, you can't mount the same parcel multiple times on the page, but you can mount multiple different parcels at the same time on the page. |
Do you have any news? I also have another issue with angular parcels: <div>
<h1></h1>
<parcel></parcel>
</div> as a result the parcel output overwrites the whole content and I get parcel output only without <div>
<content of the parcel>
</div> It works well with react parcels. |
@MRJCrunch the problem you described seems unrelated to this github issue. Please create a new issue, with a demonstration of your problem. |
@joeldenning Hello! We pass parcelId through the parcel props in the root config:
And then get it in the main.single-spa.ts singleSpaAngular function:
And send parcel id to the AppModule wrapper function, where we return a configuren module instance with custom AppComponent selector:
We need to change template field type because, when you bootstrap your AppModule and root AppComponent, angular search dom element by AppComponent selector, and it it the same, than it takes only first one. So we need to set different selectors for AppComponent on module boostraping, and they should be same with teplates in singleSpaAngular() config and different from another app parcel.
So seems that don't need alot of changes, just update field type in BaseSingleSpaAngularOptions types.ts
Update error checking in singleSpaAngular() single-spa-angular.ts
And call the template function in getContainerElementAndSetTemplate() - dom.ts
What do you think? |
single-spa passes a unique There shouldn't be a need for a workaround, the fix for this issue is not hard to implement. We just need to modify single-spa-angular like I've described above. The If you have interest in submitting a pull request for that, I would be happy to review it. But I don't have plans to work on it myself anytime soon. |
I was able to solve the given problem with no changes to the library.
|
@TarasovMV Hello, good suggestion thanks, but can you please provide a repo with this example? |
@TarasovMV: Hello! Thanks for your above solution, I was able to have multiple instances of sample app on my UI. However, I've been facing a minor issue - After the apps are mounted using above code, the changes in the angular component inside any apps are not being detected/rendered. I'm not sure if it's something with Zone, if you have faced the same issue or have any insights I'd really appreciate it. Thanks! |
Hi, we have some similiar problems, but we use angular elements - @joeldenning should I create a different bug/bugs about them? What's still missing, is the handling of the multiple elements in the options, so unmount does not work for now, but I'll fix this in the next commit. Tests and documentation should be updated also, but I wanted to see what's your reaction on the changes before I update them. |
You can create a separate github issue if it's for a different problem, but if it's the same problem then we can keep using this issue. |
I solved this problem changing the name of the selector main of my apps, for example I used I had this in main.single-spa.ts
I changed this for
and I changed the selecctor name too (app.component.ts)
now
and for last I changed the index.html
now
This error happend 'cause single-spa can't use the same parcelId with multiple parcelConfigs, you need to have a unique parceId per application |
Working with single-spa-react, my team and I encountered an issue where we couldn't instantiate multiple parcels on the same page using another parcel as a wrapper. After conducting extensive research, we discovered that using the I believe that our solution using |
Hey guys, what was the solution for that? |
We are currently trying to do this as well. I found this thread and saw that it was not possible back in 2021 when using single-spa-angular. Has this been fixed? Using a solution mentioned above by using NgDoBootstrap, I am able to get close, but updates in one parcel overwrite another instance of the same parcel config. |
Demonstration
Expected Behavior
When you mount the same single-spa-angular parcelConfig multiple times, multiple independent parcels should be created.
Actual Behavior
When you mount the same single-spa-angular parcelConfig multiple times, only one of them really works. See more at https://single-spa.slack.com/archives/CGETM8T5X/p1593605815279300
This is caused by the opts object being shared between the parcels, but it containing singleton properties. The properties should be changed to be objects/arrays that allow for multiple values (one for each parcel). Specifically
opts.bootstrappedModule
should not be a single value, but an array/object with multiple values.This bug also existed in single-spa-react and was fixed in single-spa/single-spa-react#68. The history of it is that many of the single-spa helper libraries were authored at a time when only single-spa applications existed, instead of parcels. Applications are indeed singletons, which is why there is no issue for them.
The text was updated successfully, but these errors were encountered: