cssinjs / jss

JSS is an authoring tool for CSS which uses JavaScript as a host language.
https://cssinjs.org
MIT License
7.07k stars 399 forks source link

code break in jss constructor #965

Closed yaoyao-ict closed 5 years ago

yaoyao-ict commented 5 years ago

I'm following the doc to get a basic styled React component with injectSheet, no any other api used. but it breaks in Jss constructor, complaining that this.context is undefined.

    _proto.createState = function createState() {
      var contextSheetOptions = this.context[sheetOptions];

      if (contextSheetOptions && contextSheetOptions.disableStylesGeneration) {
        return {
          classes: {}
        };
      }

      var staticSheet = this.getStaticSheet();
      var dynamicSheet = this.getDynamicSheet(staticSheet);
      return {
        staticSheet: staticSheet,
        dynamicSheet: dynamicSheet,
        classes: this.computeClasses(staticSheet, dynamicSheet)
      };
    };

and I saw this context is deliberately set to null:

    function Jss(props, context) {
      var _this;

      _this = _Component.call(this, props, context) || this;
      _this.classNamePrefix = defaultClassNamePrefix;
      _this.context = void 0;
      var contextSheetOptions = context[sheetOptions];

      if (contextSheetOptions && contextSheetOptions.classNamePrefix) {
        _this.classNamePrefix = contextSheetOptions.classNamePrefix + _this.classNamePrefix;
      }

      _this.state = _this.createState();

      _this.manage(_this.state);

      return _this;
    }

any ideas how can I fix this?

kof commented 5 years ago

This is fixed in the latest version.

On Tue, Jan 1, 2019, 07:27 yaoyao-ict <notifications@github.com wrote:

I'm following the doc to get a basic styled React component with injectSheet, no any other api used. but it breaks in Jss constructor, complaining that this.context is undefined.

_proto.createState = function createState() {
  var contextSheetOptions = this.context[sheetOptions];

  if (contextSheetOptions && contextSheetOptions.disableStylesGeneration) {
    return {
      classes: {}
    };
  }

  var staticSheet = this.getStaticSheet();
  var dynamicSheet = this.getDynamicSheet(staticSheet);
  return {
    staticSheet: staticSheet,
    dynamicSheet: dynamicSheet,
    classes: this.computeClasses(staticSheet, dynamicSheet)
  };
};

and I saw this context is deliberately set to null:

function Jss(props, context) {
  var _this;

  _this = _Component.call(this, props, context) || this;
  _this.classNamePrefix = defaultClassNamePrefix;
  _this.context = void 0;
  var contextSheetOptions = context[sheetOptions];

  if (contextSheetOptions && contextSheetOptions.classNamePrefix) {
    _this.classNamePrefix = contextSheetOptions.classNamePrefix + _this.classNamePrefix;
  }

  _this.state = _this.createState();

  _this.manage(_this.state);

  return _this;
}

any ideas how can I fix this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cssinjs/jss/issues/965, or mute the thread https://github.com/notifications/unsubscribe-auth/AADOWBFjFpaq_KbrGZwcia7fHaGorhrdks5u-vHAgaJpZM4ZlxeB .

yaoyao-ict commented 5 years ago

...thanks, this blocked me for a whole day