Skip to content
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

Only add HYDRATED_CSS when cmpTags are set #3771

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/bootstrap-lazy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export const bootstrapLazy = (lazyBundles: d.LazyBundlesRuntimeData, options: d.
});
});

if (BUILD.invisiblePrehydration && (BUILD.hydratedClass || BUILD.hydratedAttribute)) {
if (cmpTags.length > 0 && BUILD.invisiblePrehydration && (BUILD.hydratedClass || BUILD.hydratedAttribute)) {
visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
visibilityStyle.setAttribute('data-styles', '');

Expand Down
30 changes: 30 additions & 0 deletions src/runtime/test/bootstrap-lazy.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { doc } from '@platform';

import { bootstrapLazy } from '../bootstrap-lazy';

describe('assets', () => {
it('should not append broken css', () => {
const spy = jest.spyOn(doc.head, 'insertBefore');

/**
* To make the test shorter I called bootstrapLazy without any bundles
* When a user call defineCustomElements multiple times it will prevent defining the same elements within
* the bootstrapLazy method. Although this works it does still add the broken css.
*/
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,
);
});
});
Loading