Skip to content

Commit 9d60b24

Browse files
authored
Backport #3551 to v5 (#3566)
1 parent 459a8b6 commit 9d60b24

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/styled-components/src/constructors/createGlobalStyle.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,19 @@ export default function createGlobalStyle(
5151
);
5252
}
5353

54-
if (__SERVER__) {
54+
if (styleSheet.server) {
5555
renderStyles(instance, props, styleSheet, theme, stylis);
56-
} else {
56+
}
57+
58+
if (!__SERVER__) {
5759
// this conditional is fine because it is compiled away for the relevant builds during minification,
5860
// resulting in a single unguarded hook call
5961
// eslint-disable-next-line react-hooks/rules-of-hooks
6062
useLayoutEffect(() => {
61-
renderStyles(instance, props, styleSheet, theme, stylis);
62-
return () => globalStyle.removeStyles(instance, styleSheet);
63+
if (!styleSheet.server) {
64+
renderStyles(instance, props, styleSheet, theme, stylis);
65+
return () => globalStyle.removeStyles(instance, styleSheet);
66+
}
6367
}, [instance, props, styleSheet, theme, stylis]);
6468
}
6569

packages/styled-components/src/sheet/Sheet.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default class StyleSheet implements Sheet {
3131

3232
options: SheetOptions;
3333

34+
server: boolean;
35+
3436
tag: void | GroupedTag;
3537

3638
/** Register a group ID to give it an index */
@@ -50,9 +52,10 @@ export default class StyleSheet implements Sheet {
5052

5153
this.gs = globalStyles;
5254
this.names = new Map(names);
55+
this.server = !!options.isServer;
5356

5457
// We rehydrate only once and use the sheet that is created first
55-
if (!this.options.isServer && IS_BROWSER && SHOULD_REHYDRATE) {
58+
if (!this.server && IS_BROWSER && SHOULD_REHYDRATE) {
5659
SHOULD_REHYDRATE = false;
5760
rehydrateSheet(this);
5861
}

0 commit comments

Comments
 (0)