Skip to content

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

Closed
@BaoDelta

Description

@BaoDelta

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions