Skip to content

Commit

Permalink
fix: Fixed styleManager create element in ssr bug
Browse files Browse the repository at this point in the history
Close #16
  • Loading branch information
myxvisual committed Aug 9, 2017
1 parent 3bccabd commit 44cc7ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/styles/StyleManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as createHash from "murmurhash-js/murmurhash3_gc";
import IS_NODE_ENV from "../common/nodeJS/IS_NODE_ENV";
import isUnitlessNumber from "../common/react/isUnitlessNumber";

export const replace2Dashes = (key: string) => key.replace(/[A-Z]/g, $1 => `-${$1.toLowerCase()}`);
Expand Down Expand Up @@ -62,8 +63,9 @@ export class StyleManager {
}

setupStyleElement = () => {
const name = `data-uwp-jss-${this.themeId}`;
if (IS_NODE_ENV) return;
if (!this.styleElement) {
const name = `data-uwp-jss-${this.themeId}`;
this.styleElement = document.createElement("style");
this.styleElement.setAttribute(name, "");
document.head.appendChild(this.styleElement);
Expand Down
4 changes: 3 additions & 1 deletion src/styles/getTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function getTheme(themeConfig?: ThemeConfig): ReactUWP.ThemeType
},
useInlineStyle: Boolean(useInlineStyle),

styleManager: {},
styleManager: void 0,

useFluentDesign,
desktopBackground: void 0,
Expand Down Expand Up @@ -129,6 +129,7 @@ export default function getTheme(themeConfig?: ThemeConfig): ReactUWP.ThemeType
isDarkTheme: isDark,
prefixStyle: prefixAll(userAgent),
prepareStyle(config, callback) {
if (!this.styleManager) return;
const { extendsClassName, ...managerConfig } = config;
if (this.useInlineStyle) {
managerConfig.className += extendsClassName ? ` ${extendsClassName}` : "";
Expand All @@ -140,6 +141,7 @@ export default function getTheme(themeConfig?: ThemeConfig): ReactUWP.ThemeType
}
},
prepareStyles(config, callback) {
if (!this.styleManager) return;
if (this.useInlineStyle) {
const { styles } = config;
const result: any = {};
Expand Down

0 comments on commit 44cc7ca

Please sign in to comment.