javivelasco / react-css-themr

Easy theming and composition for CSS Modules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error "theme[key].indexOf is not a function" when using with isomorphic-style-loader

BaoDelta opened this issue · comments

Hi,

I am setting up some tests with mocha-webpack for my project which uses react-toolbox. Because the tests are run in node.js environment, I must use isomorphic-style-loader instead of style-loader (see webpack-contrib/style-loader#109). However, because isomorphic-style-loader adds _getCss() and _insertCss() to the imported style object, I get the error "theme[key].indexOf is not a function" from https://github.com/javivelasco/react-css-themr/blob/master/src/components/themr.js#L62:

theme[key] && style[key] && theme[key].indexOf(style[key]) === -1

It happens when key is _getCss or _insertCss and theme[key] is a function instead of a string. The fix is simple like this:

typeof theme[key] === 'string' && theme[key] && style[key] && theme[key].indexOf(style[key]) === -1

I think it is a safe check anyway. I can provide a PR if you want?

I have the same issue and this fixes it.

Of course @BaoDelta, happy to get a PR! Thanks for reporting!

@javivelasco I have created PR #7.

Merged! I'm releasing a 1.1.3 including this :)