Jss: margin: NaN crashes on Chrome 88

Created on 21 Jan 2021  路  4Comments  路  Source: cssinjs/jss

__Expected behavior:__

No crash

__Describe the bug:__

When rendering:

import * as React from "react";
import { createUseStyles } from "react-jss";

const useStyles = createUseStyles((t) => ({
  container: {
    margin: NaN
  }
}));

export default function App() {
  useStyles();
  return <div />;
}

Chrome 88 crashes. CSS.px(NaN) isn't flying well.

TypeError: Failed to execute 'px' on 'CSS': The provided double value is non-finite.

__Codesandbox link:__

https://codesandbox.io/s/react-jss-ts-forked-nl2rf?file=/src/App.tsx

__Versions (please complete the following information):__

  • jss: 10.5.0
  • Browser: Chrome >= 88

I have investigated the issue from https://github.com/mui-org/material-ui/issues/24519 and https://github.com/mui-org/material-ui/issues/24182. I'm not sure it's worth fixing here but I thought it would be interesting to report anyway.

It fails because typeof NaN === 'number':

https://github.com/cssinjs/jss/blob/94c8f6c7e5eee7ce04c31ea2f7e318a5d5b2a082/packages/jss-plugin-default-unit/src/index.js#L43

The fix should be straightforward.

Most helpful comment

All 4 comments

We are experiencing this issue too. Happy to help out with testing if needed

Fix made in https://github.com/cssinjs/jss/pull/1446. At this point, it's outside of the control of Material-UI.

Thanks @oliviertassinari & @kof, appreciate the work you guys did to figure this one!

Was this page helpful?
0 / 5 - 0 ratings