fix(dev): Append styles to head even for duplicates, fix key construction #683
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes two errors. One, simpler was introduced in this commit: 766b521 and it changed
const key = 'css__${options.name}__' + exposeItemName;
to
const key = 'css__' + options.name + '__' + exposeItemName;
which causes an error, because options.name should be resolved and not passed as a string.
The second error that this PR fixes is more complicated and I didn't think about such a case, when I introduced this feature in your project for the first time here: #548
Multiple remote components can have the same path to a CSS file with styles, becasue they can come from the same remote application (that's actually a case we have in our project). The styles between components differ very little (if at all), but the majority of styles are shared between those components and they are "base" styles like for buttons, inputs, etc. The build of such a case will consist of different federated modules, but a single CSS file.
In such a case there's a problem caused by this code fragment:
if (href in seen) return;
For styles that are appended to head, it's a correct condition, because we don't want the styles to appear more than once. However if the styles need to be appended to a Shadow Root for multiple different components, each having its own Shadow Root, then this causes a problem, because only THE FIRST loaded component will add the styles href to the window object. All the other components that want to add THE SAME styles href won't do that because of
if (href in seen) return;
. And I think it's a perfectly fine scenario with Shadow DOM usage.That's why I moved the part of the code acting when
dontAppendStylesToHead
flag is set to true to BEFORE theif (href in seen) return;
part.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).