Skip to content

Error with khan/aphrodite for CSS when manually reload #247

Closed

Description

@alexrqs
// pages/index.js
import React from 'react'
import { StyleSheet, css } from 'aphrodite'

const styles = StyleSheet.create({ h1: { color: 'crimson' } })

const header = () => <h1 className={css(styles.h1)}>Hola</h1>

export default header;

If the document is already open when you apply css(styles.h1) it takes the chages and you see the red text, but if you manually reload the browser or the application is just starting you get a 500 | Internal Server Error.

and the console will give you

Error: Cannot automatically buffer without a document
    at injectGeneratedCSSOnce (/nextApp/node_modules/aphrodite/lib/inject.js:138:23)
    at injectStyleOnce (/nextApp/node_modules/aphrodite/lib/inject.js:156:9)
    at injectAndGetClassName (/nextApp/node_modules/aphrodite/lib/inject.js:232:5)
    at css (/nextApp/node_modules/aphrodite/lib/exports.js:133:54)
    at header (/nextApp/.next/dist/pages/index.js:22:37)
    at /nextApp/node_modules/react/lib/ReactCompositeComponent.js:305:16
    at measureLifeCyclePerf (/nextApp/node_modules/react/lib/ReactCompositeComponent.js:74:12)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (/nextApp/node_modules/react/lib/ReactCompositeComponent.js:304:14)
    at ReactCompositeComponentWrapper._constructComponent (/nextApp/node_modules/react/lib/ReactCompositeComponent.js:279:21)
    at ReactCompositeComponentWrapper.mountComponent (/nextApp/node_modules/react/lib/ReactCompositeComponent.js:187:21)

I get the import style from 'next/css' but I already have another project with aphrodite modules that I'd like to reuse.

Activity

  1. nkzawa commented on Nov 13, 2016

    @nkzawa
    Contributor

    I guess the error occurs because there is no setting for server rendering of aphrodite.

    Khan/aphrodite#33

    And since there is no way to add the setting, you wouldn't be able to use the library.
    I recommend to convert your code to next/css.

  2. impronunciable commented on Nov 14, 2016

    @impronunciable
    Contributor

    @alexrqs your snippet with next/css looks like this:

    // pages/index.js
    import React from 'react'
    import css from 'next/css'
    
    const styles = { h1: { color: 'crimson' } }
    
    const header = () => <h1 className={css(styles.h1)}>Hola</h1>
    
    export default header;
  3. xymostech commented on Nov 16, 2016

    @xymostech

    @nkzawa Aphrodite does support server-side rendering. You need to wrap the server render in Aphrodite's StyleSheetServer.renderStatic instead of using glamour's renderStatic function in server/render.js

    See https://github.com/Khan/aphrodite/blob/master/README.md#server-side-rendering for more info and for instructions on how to rehydrate.

  4. rauchg commented on Nov 16, 2016

    @rauchg
    Member

    We're going to address it with #251. I don't think wrapping is a good API though. I think all SSR modules should expose a "flush" or "rewind" API

  5. locked as resolved and limited conversation to collaborators on May 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions