scoped-style
scoped-style copied to clipboard
SSR not working with Hyperapp
I'm trying to use this library in a server rendered Hyperapp app and I tried this:
// lib/style.ts
import scoped from 'scoped-style'
if (typeof global !== 'undefined') {
global.scopedStyleCSS == ''
}
const styler = (css: string) => {
if (typeof document !== 'undefined') {
scoped.defaultCallback(css)
} else if (typeof global !== 'undefined') {
global.scopedStyleCSS += css
}
}
export const styled = scoped(h, styler)
// pages/index.tsx
import { styled } from '../lib/style'
const Text = styled('p')`
font-size: 48px;
font-weight: bold;
`
export default (state: State) => <Text>Hello ${state.text}</Text>
// hyperapp code
which results in this error when trying to build in a browser-less environment:
return o2.class = t2.join(" ") + " " + (e3.class || e3.className || ""), p.name === "createElementWithValidation" && (o2.className = o2.class, delete o2.class), p(h2, o2, r2);
^
TypeError: Cannot read property 'class' of null