For compatibility with frameworks like NextJS that do server-side rendering, fix two things:
Add a CJS build, which users can import as import Pusher from 'pusher-js/cjs' or import Pusher from 'pusher-js/cjs/with-encryption'
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
[ ] All new functionality has tests.
[ ] All tests are passing.
[ ] New or changed API methods have been documented.
[X] npm run format has been run
CHANGELOG
[FIXED] Makes Pusher's browser builds compatible with server-side rendering frameworks
Closes #624
What does this PR do?
For compatibility with frameworks like NextJS that do server-side rendering, fix two things:
import Pusher from 'pusher-js/cjs'
orimport Pusher from 'pusher-js/cjs/with-encryption'
window
anddocument
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
npm run format
has been runCHANGELOG