aphrodite-jss icon indicating copy to clipboard operation
aphrodite-jss copied to clipboard

[bug?] Warning: [JSS] Could not find the referenced rule logoAndCopyright in aphrodite-jss.

Open trusktr opened this issue 6 years ago • 4 comments

I've got some styles using jss-nested with $classname syntax:

const style = StyleSheet.create({
  footer: {
    // ...

    '& $logoAndCopyright': {
      // ...
    },
  },

  logoAndCopyright: {},
})

then when I use it,

css(style.logoAndCopyright)

I get an error like

Warning: [JSS] Could not find the referenced rule logoAndCopyright in aphrodite-jss.

Full output:

Warning: [JSS] Could not find the referenced rule logoAndCopyright in aphrodite-jss.
  | warning | @ | _app.js:26063
-- | -- | -- | --
  | (anonymous) | @ | _app.js:1331
  | onProcessStyle | @ | _app.js:1393
  | onProcessStyle | @ | _app.js:3186
  | onProcessRule | @ | _app.js:3171
  | addRule | @ | _app.js:3759
  | css | @ | _app.js:211
  | render | @ | _app.js:26170
  | finishClassComponent | @ | main.js:24135
  | updateClassComponent | @ | main.js:24097
  | beginWork | @ | main.js:24766
  | performUnitOfWork | @ | main.js:26805
  | workLoop | @ | main.js:26844
  | renderRoot | @ | main.js:26884
  | performWorkOnRoot | @ | main.js:27502
  | performWork | @ | main.js:27424
  | performSyncWork | @ | main.js:27396
  | requestWork | @ | main.js:27296
  | scheduleWork$1 | @ | main.js:27160
  | scheduleRootUpdate | @ | main.js:27727
  | updateContainerAtExpirationTime | @ | main.js:27754
  | updateContainer | @ | main.js:27781
  | module.exports.webpackJsonp.../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render | @ | main.js:28064
  | (anonymous) | @ | main.js:28204
  | unbatchedUpdates | @ | main.js:27621
  | legacyRenderSubtreeIntoContainer | @ | main.js:28200
  | hydrate | @ | main.js:28256
  | renderReactElement | @ | main.js:6559
  | _callee5$ | @ | main.js:6534
  | tryCatch | @ | main.js:30206
  | invoke | @ | main.js:30440
  | prototype.(anonymous function) | @ | main.js:30258
  | step | @ | main.js:166
  | _next | @ | main.js:181
  | (anonymous) | @ | main.js:188
  | F | @ | main.js:1500
  | (anonymous) | @ | main.js:161
  | _doRender | @ | main.js:6551
  | doRender | @ | main.js:6433
  | _callee2$ | @ | main.js:6339
  | tryCatch | @ | main.js:30206
  | invoke | @ | main.js:30440
  | prototype.(anonymous function) | @ | main.js:30258
  | step | @ | main.js:166
  | _next | @ | main.js:181
  | (anonymous) | @ | main.js:188
  | F | @ | main.js:1500
  | (anonymous) | @ | main.js:161
  | _render | @ | main.js:6369
  | render | @ | main.js:6311
  | _callee$ | @ | main.js:6290
  | tryCatch | @ | main.js:30206
  | invoke | @ | main.js:30440
  | prototype.(anonymous function) | @ | main.js:30258
  | step | @ | main.js:166
  | _next | @ | main.js:181
  | Promise.then (async) |   |  
  | step | @ | main.js:176
  | _next | @ | main.js:181
  | Promise.then (async) |   |  
  | step | @ | main.js:176
  | _next | @ | main.js:181
  | Promise.then (async) |   |  
  | step | @ | main.js:176
  | _next | @ | main.js:181
  | (anonymous) | @ | main.js:188
  | F | @ | main.js:1500
  | (anonymous) | @ | main.js:161
  | ../node_modules/next/dist/client/next-dev.js | @ | main.js:6592
  | __webpack_require__ | @ | manifest.js:715
  | fn | @ | manifest.js:118
  | 0 | @ | main.js:35329
  | __webpack_require__ | @ | manifest.js:715
  | webpackJsonpCallback | @ | manifest.js:26
  | (anonymous) | @ | main.js:2

trusktr avatar Sep 05 '18 19:09 trusktr

Seems like I'm doing things correctly, because if I modify my component from using aphrodite-jss,

import {StyleSheet, css} from 'aphrodite-jss'
import {Component} from 'react'

export default
class Foo extends Component {
  render() {
    return <div className={css(classes.footer)}>
      <div className={css(classes.logoAndCopyright)} />
    </div>
  }
}

const classes = StyleSheet.create({
  footer: {
    // ...

    '& $logoAndCopyright': {
      // ...
    },
  },

  logoAndCopyright: {},
})

to using plain JSS (from react-jss), then it works great:

import {jss} from 'react-jss'
import {Component} from 'react'

export default
class Foo extends Component {
  render() {
    return <div className={classes.footer}>
      <div className={classes.logoAndCopyright} />
    </div>
  }
}

const {classes} = jss.createStyleSheet({
  footer: {
    // ...

    '& $logoAndCopyright': {
      // ...
    },
  },

  logoAndCopyright: {},
}).attach()

So seems something isn't working in aphrodite-jss.

trusktr avatar Sep 05 '18 19:09 trusktr

I think the problem is the order of evaluation. The rules are lazily attached, which means the rules are only attached once css is being called with them. The footer rule is being attached before the logoAndCopyright rule, which results in the warning.

I don't know if we can fix this. You can just call css(classes.logoAndCopyright) before which should fix your problem.

HenriBeck avatar Sep 05 '18 20:09 HenriBeck

Hmmm, that may be a strange caveat. It'd be nice to fix it. Well I've switched to react-jss because I was able to get that to work with SSR in the other thread, and to use aphrodite-jss I would have to solve the same problem again for aphrodite-jss.

trusktr avatar Sep 05 '18 21:09 trusktr

As I see - it's old issue - but maybe somebody gonna looking for solution as I - to resolve this I moved style Initialization inside of component body

kuzmenko-tgn avatar Apr 27 '21 19:04 kuzmenko-tgn