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

With-Aphrodite example renders styles twice in the <head> #1853

Closed
spencersmb opened this issue May 2, 2017 · 3 comments
Closed

With-Aphrodite example renders styles twice in the <head> #1853

spencersmb opened this issue May 2, 2017 · 3 comments

Comments

@spencersmb
Copy link
Contributor

I've been looking at Aphrodite - downloaded the example and started up the dev. I noticed that in the head tag the styles are getting added twice.

This is what shows up from the example:


<style>.root_16xsm7s{width:80px !important;height:60px !important;background:white !important;}.root_16xsm7s:hover{background:black !important;}.title_1nde1x4{margin-left:15px !important;color:black !important;font-size:22px !important;}.title_1nde1x4:hover{color:white !important;}</style>
<style type="text/css" data-aphrodite="">.root_16xsm7s{width:80px !important;height:60px !important;background:white !important;}.root_16xsm7s:hover{background:black !important;}.title_1nde1x4{margin-left:15px !important;color:black !important;font-size:22px !important;}.title_1nde1x4:hover{color:white !important;}</style>

Any ideas why the duplicate?

@sergiodxa
Copy link
Contributor

If you change inside pages/_document.js the style tag to add the data-aphrodite="" prop then it's not generating two style tags.

import Document, { Head, Main, NextScript } from 'next/document'
import { StyleSheetServer } from 'aphrodite'

export default class MyDocument extends Document {
  static async getInitialProps ({ renderPage }) {
    const { html, css } = StyleSheetServer.renderStatic(() => renderPage())
    return { ...html, css }
  }

  render () {
    return (
      <html>
        <Head>
          <title>My page</title>
          <style dangerouslySetInnerHTML={{ __html: this.props.css.content }} data-aphrodite="" />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </html>
    )
  }
}

But it's going to put the same class two times inside the style tag.

.root_16xsm7s{width:80px !important;height:60px !important;background:white !important;}.root_16xsm7s:hover{background:black !important;}.title_1sfv8vd{margin-left:5px !important;color:black !important;font-size:22px !important;}.title_1sfv8vd:hover{color:white !important;}
.root_16xsm7s{width:80px !important;height:60px !important;background:white !important;}.root_16xsm7s:hover{background:black !important;}.title_1sfv8vd{margin-left:5px !important;color:black !important;font-size:22px !important;}.title_1sfv8vd:hover{color:white !important;}

@aranajhonny
Copy link
Contributor

aranajhonny commented May 3, 2017

We found the solution in #next. Waiting for the PR.

@spencersmb
Copy link
Contributor Author

This PR solves our issue:
#1858

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018
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

3 participants