pusher / pusher-js

Pusher Javascript library
http://pusher.com
MIT License
2.1k stars 371 forks source link

For SSR compatibility, add CJS build and guard global variable access #819

Open AlexVipond opened 4 months ago

AlexVipond commented 4 months ago

Closes #624

What does this PR do?

For compatibility with frameworks like NextJS that do server-side rendering, fix two things:

  1. Add a CJS build, which users can import as import Pusher from 'pusher-js/cjs' or import Pusher from 'pusher-js/cjs/with-encryption'
  2. Add guard clauses so that global variables like window and document are not accessed in server environments, where they don't exist.

These two changes allow SSR framework users to import Pusher with a reasonably industry-standard DX, without breaking their apps or resorting to dynamic imports.

Checklist

CHANGELOG