question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect "Rule is not linked" warning on server when using function rules

See original GitHub issue

Expected behavior: No warning.

Describe the bug: All function rules are triggering the following warning when run on the server: Warning: [JSS] Rule is not linked. Missing sheet option “link: true”.

I’ve traced the problem back to the fact that in Jss.js, options.Renderer is set to null when not in the browser. This eventually leads to the code in BaseStyleRule.prop() falling through to the warning because this.renderable and this.renderer are not defined at styleRule.js#L71.

The warning is incorrect: the sheet option link is actually true, and the fact that this.renderable and this.renderer are not defined is correct because on the server, we don’t need anything to happen in prop() because we’ll call toString() later the render the CSS.

I would contribute a test to replicate the bug, but I don’t think it’s possible with the existing karma setup because we need 'is-in-browser' to report false to trigger the bug. So, I’ve written a jest test (see link below) to demonstrate.

Codesandbox link: https://repl.it/@felthy/JssInvalidWarningDuringSSR

Versions:

  • jss: 10.0.0-alpha.20

jest test source:

/**
 * @jest-environment node
 */
import warning from 'tiny-warning'
import {create, SheetsRegistry, SheetsManager} from 'jss/dist/jss.cjs'
import functionPlugin from 'jss-plugin-rule-value-function/dist/jss-plugin-rule-value-function.cjs'
import isInBrowser from 'is-in-browser'

jest.mock('tiny-warning')

describe('React-JSS: rendering in an SSR context', () => {
  it('should render a dynamic rule without warnings', () => {
    expect(isInBrowser).toBe(false)

    const jss = create().use(functionPlugin())
    const sheet = jss.createStyleSheet({
      rule: () => ({
        color: 'red'
      })
    }, {
      link: true
    }).attach()
    sheet.update({})
    const css = sheet.toString()

    expect(css).toContain('color: red;')
    expect(warning).not.toHaveBeenCalled()
  })
})

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
hanayashikicommented, Mar 4, 2021

Still get this annoying warning on the server side. Any solutions?

0reactions
benistarycommented, Mar 28, 2022

Exact problem. Any news?

Next 12.1.0 React-jss 10.9.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create custom actions rules in Outlook for Windows
A rule is an action that Outlook automatically performs on sent or received email messages, based on conditions you specify, such as moving...
Read more >
Enables functions for dynamic styles - JSS
If you want dynamic behavior for your Style Sheet, you can use functions as a value which return the actual value or a...
Read more >
tslint how to disable error "someVariable is declared but its ...
Use _myVariable instead of myvariable to remove this warning. ... So, I removed the no-unused-variable rule fromt tslint.json - and that ...
Read more >
Invalid Hook Call Warning - React
🔴 Do not call Hooks inside functions passed to useMemo , useReducer , or useEffect . If you break these rules, you might...
Read more >
Custom Lambda Rules (General Example) - AWS Config
If the Lambda function is associated with a Config rule, AWS Config invokes it when the rule's trigger occurs. The Lambda function then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found