isomorphic-style-loader icon indicating copy to clipboard operation
isomorphic-style-loader copied to clipboard

Helper method _getCSS() not added on Node server while it works on client side

Open abhishek7singh opened this issue 6 years ago • 2 comments

The isomorphic style loader works fine on client side ( using webpack build), but when I run code on exress server, I get the other style does not have function _getCSS() .

On debugging the style object, its value is the list of styles mentioned in the scss file. So it seems the helper method is not added.

Also, I searched for _getCSS reference on my code, _getCSS & _insertCSS are present in main.js and that is the reason it works on client side. But while compiling on node, I am not sure when(which part of build process) does the helper method _getCSS should get added.

abhishek7singh avatar Oct 15 '18 12:10 abhishek7singh

You need self-implemented insertCss and pass it to context. There is a good example in the README.

server.get('*', (req, res, next) => {
  const css = new Set(); // CSS for all rendered React components
  const context = { insertCss: (...styles) => styles.forEach(style => css.add(style._getCss())); };
  // ...

piglovesyou avatar Feb 17 '19 22:02 piglovesyou

@abhishek7singh did you resolve this problem? I have the same problem. It seems _getCss function is not added to style object by ISL loader. I have implemented insertCss on SSR (like in readme) and it's called fine, where style – is an object of my component's classnames but without _getCss method

TotallWAR avatar Jan 15 '20 12:01 TotallWAR