Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

plugin-less instantiates CSSPluginBase() when it is not running in a browser. #6

@mikol-styra

Description

@mikol-styra

I am trying (unsuccessfully) to use plugin-less in conjunction with server-side rendering. The root cause of the problem is CSSPluginBase.prototype.instantiate(), which attempts to inject a style element into the DOM without document being defined:

CSSPluginBase.prototype.instantiate = function(load) {
  if (this.builder)
    return;

  var style = document.createElement('style');
  style.type = 'text/css';
  style.innerHTML = load.metadata.style;
  document.head.appendChild(style);
};

module.exports = CSSPluginBase;

I am not sure what the correct fix is in this case. There may be two. First, explicitly checking if document is defined in CSSPluginBase.prototype.instantiate() seems appropriate and works for me in practice:

  if (this.builder || typeof document === 'undefined')
    return;

Second, less.js may require a fix so that the CSSPluginBase() constructor is not even called unless plugin-less is running in a browser. plugin-css explicitly checks if it is running in a browser, for example, and does not have an issue with server-side rendering. Neither does mobilexag/plugin-sass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions