-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Single-SPA 2 applications example #380
Comments
Hey, @philearley. Thanks for reaching out. I don't have experience with Single SPA, but from what I can gather it looks like both of your "micro-services" register the worker from MSW, and that causes the problem. Since each such service is a standalone app, it makes sense to have an MSW setup individually, especially if those apps are in different repositories. However, no matter how many apps this frameworks puts together, it's still a single client (tab) from the worker's perspective. Having multiple same-purposed workers on a single client isn't a good idea, as it subjects their operation to race conditions and all sorts of strange behavior, which I think you're experiencing. What to doCheck the clientsI don't have an exact setup to recommend here, so we'd have to experiment. I wonder if the map of client IDs is different in those two workers? You can check that by modifying your both worker scripts to log out this variable into the browser's console: Line 13 in 5d842c5
Each worker instance keeps a map of client IDs (tab IDs) controlled by that worker. In other words, those are references to tabs that registered/activated that worker. Upon each request the running worker checks if the client that sends a request is present in the map of Lines 95 to 96 in 5d842c5
Technically, if each app registers it own worker and produces a unique client ID, there should be no issue. What I'm afraid is happening is that the client ID is assigned per tab, and since you're loading both apps in a single tab, both workers will store that tab as their controlled client. If that's the case, I don't think there's much we can do, as that's not how service worker are designed to be used. Versioning
Could you please share the exact error you get? |
@kettanaito thank you for responding. In regards to the error we get it's this one, msw/src/setupWorker/start/utils/getWorkerInstance.ts Lines 78 to 80 in 2943c08
As you mentioned, because both workers are present both handlers are intercepting the request. I think both issues are linked though, based on what you're saying about the id's being based on the tab they are generated from. I should have some more time to investigate this week, I'll see what is happening around the id's and see if we can find a solution/work around. Will report back findings and go from there. |
Sorry, but I don't have a proper suggestion for this at the moment. Feel free to contribute here if you find out the right way to integrate MSW into a Single-SPA project. Most of the time it's the issue with properly placing or serving the worker script. |
@philearley - were you able to get micro-frontend / federated frontend setup to work with MSW? Other References
|
Hey, apologies if this question should be asked in a different forum.
I am using Single-SPA https://single-spa.js.org/
We have 2 repos loaded in this environment and while we wait for the api's to be written, we're using the browser to demo what we have in master.
We have two challenges:
Have I missed something in the documentation that can cater for the above?
Or do you have some ideas in handling this scenario?
The text was updated successfully, but these errors were encountered: