-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime): only generate lazy build CSS when there are component t…
…ags (#5305) * fix(runtime): only generate lazy build CSS when there are component tags This commit fixes an issue where invalid CSS could be generated and inserted into the DOM if `bootstrapLazy` was called with no component metadata or if no new components are registered in the custom element registry (i.e. it is called multiple times with the same metadata). STENCIL-632 Closes: #3771 Co-authored-by: Robin Aldenhoven <[email protected]> * remove prehydration tests This commit removes some "invisible prehydration" tests that no longer work based on changes in 2559917. They no longer work because `bootstrapLazy` is called with the same compiler metadata so styles are not re-inserted after being manually removed by calls to `tearDownStylesScripts` in the respective test files * chore(karma): remove additional invisilbePrehydration infra * mark todo --------- Co-authored-by: Robin Aldenhoven <[email protected]> Co-authored-by: Ryan Waskiewicz <[email protected]>
- Loading branch information
1 parent
9d9fe41
commit a0c1bd0
Showing
10 changed files
with
87 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { doc } from '@platform'; | ||
|
||
import { LazyBundlesRuntimeData } from '../../internal'; | ||
import { bootstrapLazy } from '../bootstrap-lazy'; | ||
|
||
describe('bootstrap lazy', () => { | ||
it('should not inject invalid CSS when no lazy bundles are provided', () => { | ||
const spy = jest.spyOn(doc.head, 'insertBefore'); | ||
|
||
bootstrapLazy([]); | ||
|
||
expect(spy).not.toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
sheet: expect.objectContaining({ | ||
cssRules: [ | ||
expect.objectContaining({ | ||
// This html is not valid since it does not start with a selector for the visibility hidden block | ||
cssText: '{visibility:hidden}.hydrated{visibility:inherit}', | ||
}), | ||
], | ||
}), | ||
}), | ||
null, | ||
); | ||
}); | ||
|
||
it('should not inject invalid CSS when components are already in custom element registry', () => { | ||
const spy = jest.spyOn(doc.head, 'insertBefore'); | ||
|
||
const lazyBundles: LazyBundlesRuntimeData = [ | ||
['my-component', [[0, 'my-component', { first: [1], middle: [1], last: [1] }]]], | ||
]; | ||
|
||
bootstrapLazy(lazyBundles); | ||
expect(spy).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
sheet: expect.objectContaining({ | ||
cssRules: [ | ||
expect.objectContaining({ | ||
cssText: 'my-component{visibility:hidden}.hydrated{visibility:inherit}', | ||
}), | ||
], | ||
}), | ||
}), | ||
null, | ||
); | ||
|
||
bootstrapLazy(lazyBundles); | ||
expect(spy).not.toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
sheet: expect.objectContaining({ | ||
cssRules: [ | ||
expect.objectContaining({ | ||
// This html is not valid since it does not start with a selector for the visibility hidden block | ||
cssText: '{visibility:hidden}.hydrated{visibility:inherit}', | ||
}), | ||
], | ||
}), | ||
}), | ||
null, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
test/karma/test-app/invisible-prehydration-default/index.html
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
test/karma/test-app/invisible-prehydration-default/karma.spec.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
test/karma/test-app/invisible-prehydration-true/karma.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
test/karma/test-invisible-prehydration/stencil.invisiblePrehydrationTrue.config.ts
This file was deleted.
Oops, something went wrong.