Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Breaks in SSR #80

Open
mvasin opened this issue Jul 21, 2020 · 1 comment
Open

Breaks in SSR #80

mvasin opened this issue Jul 21, 2020 · 1 comment

Comments

@mvasin
Copy link

mvasin commented Jul 21, 2020

The library breaks when used in a server-side rendered app. The build breaks with ReferenceError: window is not defined error, and a check typeof window === 'undefined' && ... unfortunately doesn't help.

@verydanny
Copy link

You should turn the lib into a string and serve it with your SSR app. I'm assuming you're using something like React here.

Something like so:

import fontFaceOnLoad from 'fontfaceonload'
import { renderToString } from 'react-dom/server'
import { html } from 'common-tags'

const app = renderToString(<App/>)

const html = html`
  <!DOCTYPE html>
  <html lang="en">
  <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
      <script type="application/javascript">
        ${fontFaceOnLoad}
      </script>
  </head>
  <body>
    <div id="app-root">${app}</div>
  </body>
  </html>
`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants