Detalhes do pacote

ssr-window

nolimits4web4mMIT5.0.0

Better handling for window object in SSR environment

ssr, window, document

readme (leia-me)

SSR Window

Better handling for window and document object in SSR environment.

This library doesn't implement the DOM (like JSDOM), it just patches (or creates window and document objects) to avoid them to fail (throw errors) during server-side rendering.

Was created for use in:

Installation

Library available on NPM:

npm i ssr-window

Usage

import { window, document } from 'ssr-window';

window.addEventListener('resize', () => {});

const div = document.querySelectorAll('div');

Extending

If you rely on some window/document properties which are not included here, you can use extend helper to add them:

import { window, document, extend } from 'ssr-window';

// add window.navigator.language
extend(window, {
  navigator: {
    language: 'en',
  },
});

// add document.body
extend(document, {
  body: {
    /* ... */
  },
});

Contribution

Yes please! See the contributing guidelines for details.

Licence

This project is licensed under the terms of the MIT license.

changelog (log de mudanças)

Change Log

5.0.0 (2025-02-12)

Bug Fixes

  • fix prototype pollution (46468a4)

Features

4.0.2 (2021-12-13)

Features

4.0.1 (2021-10-27)

Features

  • add "main" and "module" package.json fields (bc2984a)

4.0.0 - Released on August 25, 2021

  • Increase build target to es6
  • Now package uses only exports field which exports ES module

4.0.0-beta.3 - Released on August 4, 2021

  • Increase build target to es6

4.0.0-beta.1 - Released on July 22, 2021

  • Now package uses only exports field which exports ES module

3.0.0 - Released on November 9, 2020

  • Now it uses getter functions for window and document to not to polute existing scope:

    import { getWindow, getDocument } from 'ssr-window';
    
    const window = getWindow();
    const document = getDocument();

2.0.0 - Released on May 12, 2020

  • Now it uses patching instead of creating window and document if they are already available
  • Added extend method

1.0.1 - Released on July 18, 2018

  • Simplified code structure to bypass rollup bugs