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.

Specific style causes infinite loop

See original GitHub issue

Current behavior:

When I add a the style <div css={{ width: 'stackWidth' }} />, the app crashes in an infinite loop and the error

RangeError: Maximum call stack size exceeded

To reproduce:

  1. Go to this Sandbox: https://codesandbox.io/s/emotion-issue-template-forked-st77g?file=/src/index.js:464-572
  2. Uncomment JSX on line 18 to 20.
  3. Error should appear in browser tab within Sandbox

Expected behavior:

The (incorrect) CSS width: stackWidth; should be applied to the element without throwing an error.

Environment information:

  • react version: v16.8.6 but seems to happen with all React versions
  • @emotion/react version: v11.1.1

More info to bug:

The infinite loop is caused by the stylis prefixer. The prefix function is called with the value width:stackWidth; and length 5 which results in the hashed value 8116. In the switch statement in the case of 8116 the prefix function is called again, causing an infinite recursion.

Background:

The issue came up while testing a component using (a yet unreleased version of) Theme UI.

The Theme UI library uses Emotion behind the scene and allows to use styles like <div sx={{ width: 'stackWidth' }} /> where the CSS value for the width will be resolved through a theme put into the Emotion context, so that Emotion receives <div css={{ width: 560 }} />.

The bug came up in a test where a component using Theme UI was rendered. This component was not wrapped in a theme provider, so the value 'stackWidth' could not be resolved and Emotion received <div css={{ width: 'stackWidth' }} />.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Dec 1, 2020

The fix for this issue has just been released in stylis@4.0.4

1reaction
Andaristcommented, Nov 18, 2020

Thank you for the detailed repro case! I will forward this issue to Stylis - not yet sure how to best handle this given the Stylis generally assumes valid CSS and it cares about its bundlesize greatly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - what is the design flaw causing the infinite loop in this ...
I've created a basic React component as a sandbox. I added a doSomething() function to the component which simply displays an alert on...
Read more >
5 useEffect Infinite Loop Patterns | by Naveen DA
In general, infinite loops are considered bad practices. But in some edge cases, you don't have any choice to choose rather than an...
Read more >
Loops in CSS Preprocessors | CSS-Tricks
While loops are generic, and will keep looping while any condition is met. Be careful! This is where infinite loops are most likely....
Read more >
Functional style for infinite loop - Design - Scala Users
With the code being based on Java threads and having side effects as its only result, it's pretty non-functional to start with. :slight_smile:....
Read more >
Class: RuboCop::Cop::Style::InfiniteLoop - Doc Index
Class: RuboCop::Cop::Style::InfiniteLoop ... Use Kernel#loop for infinite loops. ... Adds an offense on the specified range (or node with an expression) ...
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