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

Add isBrowser as a property of sheet so that it can be manually set. #377

Merged
merged 3 commits into from
Oct 4, 2017
Merged
Changes from 2 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
9 changes: 4 additions & 5 deletions packages/emotion/src/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ function sheetForTag(tag) {
}
}

const isBrowser: boolean = typeof window !== 'undefined'

function makeStyleTag() {
let tag = document.createElement('style')
tag.type = 'text/css'
Expand All @@ -48,6 +46,7 @@ function makeStyleTag() {

export default class StyleSheet {
constructor() {
this.isBrowser = typeof window !== 'undefined'
this.isSpeedy = process.env.NODE_ENV === 'production' // the big drawback here is that the css won't be editable in devtools
this.tags = []
this.ctr = 0
Expand All @@ -56,7 +55,7 @@ export default class StyleSheet {
if (this.injected) {
throw new Error('already injected!')
}
if (isBrowser) {
if (this.isBrowser) {
this.tags[0] = makeStyleTag()
} else {
// server side 'polyfill'. just enough behavior to be useful.
Expand All @@ -72,7 +71,7 @@ export default class StyleSheet {
this.isSpeedy = !!bool
}
insert(rule, sourceMap) {
if (isBrowser) {
if (this.isBrowser) {
// this is the ultrafast version, works across browsers
if (this.isSpeedy) {
const tag = this.tags[this.tags.length - 1]
Expand Down Expand Up @@ -101,7 +100,7 @@ export default class StyleSheet {
}
}
flush() {
if (isBrowser) {
if (this.isBrowser) {
this.tags.forEach(tag => tag.parentNode.removeChild(tag))
this.tags = []
this.ctr = 0
Expand Down