1.1.15 • Published 3 days ago

@devtea2026/dolore-sapiente-facere-inventore v1.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

@devtea2026/dolore-sapiente-facere-inventore

ESLint plugin that detects incorrect use of DOM globals in order to properly do SSR and in general share code between client-side JS and Node.js modules.

npm version

Installation

npm i --save-dev @devtea2026/dolore-sapiente-facere-inventore

Then add these to your eslintrc configuration:

{
  "plugins": ["ssr-friendly"],
  "extends": ["plugin:ssr-friendly/recommended"]
}

Rules

no-dom-globals-in-module-scope

Disallow use of DOM globals in module and global scope, as this will break any import/require in a NodeJS environment.

To fix it, wrap it in a function that will call when on client-side.

Please note that we can't detect if you're still calling this function without properly checking upfront if typeof window !== "undefined".

Not allowed

const retina = devicePixelRatio > 2;

Allowed

const isRetina = () => devicePixelRatio >= 2;

no-dom-globals-in-constructor

Disallow use of DOM globals in class constructors, as this will break SSR if you're instantiating this class as singleton or you're rendering this component.

To fix it, move this statement in a initOnBrowser() like-method or componentDidMount() if you're using React.

Please note that we can't detect if you're still calling this function in your constructor without properly checking upfront if typeof window !== "undefined".

Not allowed

class myClass {
  constructor() {
    document.title = "Otto";
  }
}

Allowed

class myClass {
  componentDidMount() {
    document.title = "Otto";
  }
}

no-dom-globals-in-react-cc-render

Disallow use of DOM globals in render() method of a React class-component, as this will break SSR if you're rendering this component.

To fix it, move this statement to componentDidMount()

Please note that we can't detect if you're still calling this function in your constructor without properly checking upfront if typeof window !== "undefined".

Not allowed

class Header extends React.Component {
  render() {
    const width = window.innerWidth;
    return <div style={{ width }} />;
  }
}

Allowed

class Header extends React.Component {
  componentDidMount() {
    this.setState({ width: window.innerWidth });
  }
  render() {
    return <div style={{ width }} />;
  }
}

no-dom-globals-in-react-fc

Disallow use of DOM globals in the render-cycle of a React FC, as this will break SSR if you're rendering this component.

To fix it, move this statement into a useEffect())

Not allowed

const Header = () => {
  window.addEventListener("resize", () => {});
  return <div />;
};

Allowed

const Header = () => {
  useEffect(() => {
    window.addEventListener("resize", () => {});
  }, []);
  return <div />;
};
mapreducepreprocessornodeinternal slotcss variablereadablestreamtextutilfilterargsclonemkdirsflagcore-jsECMAScript 2015fullwidthextendPushomitstylesheetgroupByinFloat64Arraypolyfillfastcloneopencjktypesafereact-testing-librarysetterbrowserslistUint8ClampedArraygetoptquerybyteOffsetbrowserjoiwrapfstyped arrayloggerfast-deep-clonegradients cssmacossymbolECMAScript 7256emojibyteLengthenderboundjapanesereduxshampromisenodejsInt32Arraytakejsdifffastifyreadawsequalrandoml10npicomatchwindowsratelimitagentdependenciesansistringifierio-tswhichflatMaplintslotpatchTypeBoxhigher-orderbatchlesscsssharedarraybuffershimequalityviewbcryptdebuggeroptimizerdeepcloudtrailiterationObservableUint8Arrayprocessautoscalinglook-upinferencecurlbusygenericsthrottleRFC-6455terminalkinesisfixed-widthUint16Arrayes2015multi-packagejwtgradients css3unicodeStreampackagesrm -rfes7momentponyfillhardlinkshttppositivecall-bindescapepluginrm -fres2018setImmediateESsqsexit-codeyamlregular expressionjavascriptwatchFilespeedwatchingdirURLSearchParams__proto__real-timefunctions_.extendArrayBuffer#slicesigintfrombannerSetECMAScript 6upArray.prototype.findLastIndexmimeincludesrequestdeep-copyReactiveXinspectfigletbundlermodulesshrinkwrapdependency managerrdsclass-validatorenvironmentsiecontainsimportexportcodesuninstalldynamodbString.prototype.matchAllRxUnderscorehas-owndatees8ES8packageES2023groupefficientsimpledbtypanionFunction.prototype.namepersistentlistenersCSSimportmetadatapostcssawaitelasticachestatenegativeworkerSymbol.toStringTagloadingjsonpathpredictableindicatortypedarraysqueuepackage managercloudwatchAsyncIteratorreadableswfschemeinternalcensorpropertiesenumerableclassnamesJSONfindLastUint32ArraysinatrastringifyparseremovenopestylesecmascripttypedarrayflattentelephonemimetypesregexhasOwnreplayESnextinputbufferstestingforEachstreamsless csselbcallWeakSetwaf0idasciisyntaxerrormovedatastructureparserbootstrap cssArray.prototype.findLastfunctionalWebSocketreactresolveparsingtypeofcopytypeerrorbluebirdargvregular expressionsemiteveryArray.prototype.filterrfc4122objectvisualtsinterruptsparentssettings[[Prototype]]cloudformationxtermiteratorreact-hook-formwaittypescriptajaxeventDispatchercolumnscorees-abstractrecursiveutilityrestsearchinvariantmixinscharacternpmYAMLcreatedefinePropertyreducestringproxyidledom-testing-librarylimitedrgbcryptobootstrap lessarrayeventsstreams2hooksstructuredClonesignalgraphqlshebangfastES2016fulldeletetoobjectbddmappropertymkdirES6uuidastirqmodulefunctionjestlinksessameValueZeroECMAScript 2016installerES3$.extendprotocol-buffersFloat32ArrayeslintregexpArray.prototype.flatconnectArrayBufferMapdiffjsthroatlessjshinti18nkeycallbindautoprefixerclasseswordbreakoutputTypeScriptreducercollectionvarsspinnertypehashnativeasserttoSortednested csslinewraprequiredeep-clonetouchregularargparseform-validationcolorsrmdirexitlogcachepushhttpstypeswalkingprotobufkeysES2018es2017signalsfindprivatebyteRxJSdefinevalidatees5nameECMAScript 5webs3estreegdprSymbolchrometc39collection.es6mochaelectronless mixinsvalidationdirectorysorteddataViewinstallhelperskarmagetOwnPropertyDescriptorsymlinksfindLastIndexECMAScript 2023getPrototypeOfloggingfile systemprunescheme-validationeslintpluginsortArrayBuffer.prototype.sliceObject.entriesnumbervaluesserializationdeterministicdayjsimmerURLformatschemaObject.definePropertyrapidcss nestingprivate datatapInt16Arrayexpressdataviewemrmkdirpfast-copywritableObjectpostcss-pluginqueueMicrotaskenvString.prototype.trimduplexroutermiddlewareweaksetArray.prototype.flatMaplruloadbalancingObject.getPrototypeOfyupesformattingreuseCSSStyleDeclarationoptimistfastcopyminimallengthfindupwgetIteratorwidthstdlibstyled-componentscallbacka11yhottoStringTagcssspecRegExp#flagstraversesuperstructsuperagenttaskformsdeepcopyarraysmatchAllawesomesaucegetairbnbPromiseclientutilitiesBigUint64Arrayless.jsiamfast-cloneStyleSheetassertsartlibphonenumbercolumnquerystringes6koreancolourapiruntimeappweakmapvalueargumentec2callboundrangeerrorcloudfrontsnsperformantless compilerlastgetintrinsices2016accessoreast-asian-widthfpssetPrototypeOfsigtermclivalidcode pointscommandfull-widthassertionECMAScript 2022isConcatSpreadableES2020domWeakMapconsoleserializertapeurljsxpackage.jsonglacierES2017lockfilechineseformfluxjQuerybufferes-shimsArray.prototype.containsreact-hooksasyncpromisestoArrayHyBimatchesonceiteratettywatcher
1.1.15

3 days ago

1.1.14

4 days ago

1.1.13

5 days ago

1.1.12

6 days ago

1.1.11

7 days ago

1.1.10

8 days ago

1.1.9

9 days ago

1.1.8

10 days ago

1.1.7

11 days ago

1.1.6

12 days ago

1.0.6

13 days ago

1.0.5

14 days ago