You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a single-spa environment, where multiple micro-apps coexist within the same application, managing the styles of each micro-app can be challenging. The default behavior of Webpack's style-loader plugin is to append a <style> tag to the document head when the micro-app is loaded. However, this tag is not removed when the micro-app is unmounted, leading to potential conflicts and unintended styling effects across the application.
Proposed Solution
To address this issue, we propose the following solution:
Root App Event Handling:
Implement a built-in event handler in single-spa that listens for the single-spa:before-routing-event.
This event handler should remove and store the <style> tag when a micro-app is unmounted, using a Map to maintain a cloned copy of the styles.
When a micro-app is mounted, the event handler should restore the previously stored styles by appending the cloned <style> tag to the document head.
To make this work, the developer should change the configuration option for the style-loader that allows to generate a unique ID for a unique <style> tag, tied to the micro-app's name.
Example configuration:
Integrate this functionality as a built-in feature or plugin for single-spa, allowing developers to easily configure the desired behavior for their micro-apps' styles.
Provide a centralized approach to managing micro-app styles, reducing the need for individual implementations across projects.
Benefits
Implementing this solution within single-spa would provide the following benefits:
Style Isolation: Micro-app styles would be effectively isolated, preventing conflicts and unintended styling effects across the application. Centralized Management: A centralized approach to managing micro-app styles would reduce the need for individual implementations across projects. Configurable: Developers would have the flexibility to choose which micro-apps should have their styles recycled, based on their specific requirements.
Considerations
Performance Impact:
The proposed solution involves cloning and appending/removing <style> tags on every routing event, which may have potential performance implications.
It is recommended to conduct performance tests and monitoring to determine the actual impact on specific use cases.
The text was updated successfully, but these errors were encountered:
Hi, there is definitely work to do in simplifying the asset handling, scoping, etc.
However, in my opinion, putting this behavior in the single-spa library might not be the right place.
Microfrontends should clean up the resources in the unmount lifecycle hook. Potentially, it could be offered as some kind of a "plugin" in a lifecycle helper.
Problem Statement
In a single-spa environment, where multiple micro-apps coexist within the same application, managing the styles of each micro-app can be challenging. The default behavior of Webpack's style-loader plugin is to append a <style> tag to the document head when the micro-app is loaded. However, this tag is not removed when the micro-app is unmounted, leading to potential conflicts and unintended styling effects across the application.
Proposed Solution
To address this issue, we propose the following solution:
Root App Event Handling:
Implement a built-in event handler in single-spa that listens for the single-spa:before-routing-event.
This event handler should remove and store the <style> tag when a micro-app is unmounted, using a Map to maintain a cloned copy of the styles.
When a micro-app is mounted, the event handler should restore the previously stored styles by appending the cloned <style> tag to the document head.
Example implementation:
Webpack Configuration:
To make this work, the developer should change the configuration option for the style-loader that allows to generate a unique ID for a unique <style> tag, tied to the micro-app's name.
Example configuration:
Integration with single-spa:
Integrate this functionality as a built-in feature or plugin for single-spa, allowing developers to easily configure the desired behavior for their micro-apps' styles.
Provide a centralized approach to managing micro-app styles, reducing the need for individual implementations across projects.
Benefits
Implementing this solution within single-spa would provide the following benefits:
Style Isolation: Micro-app styles would be effectively isolated, preventing conflicts and unintended styling effects across the application.
Centralized Management: A centralized approach to managing micro-app styles would reduce the need for individual implementations across projects.
Configurable: Developers would have the flexibility to choose which micro-apps should have their styles recycled, based on their specific requirements.
Considerations
Performance Impact:
The proposed solution involves cloning and appending/removing <style> tags on every routing event, which may have potential performance implications.
It is recommended to conduct performance tests and monitoring to determine the actual impact on specific use cases.
The text was updated successfully, but these errors were encountered: