Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexVipond
Copy link

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

  • All new functionality has tests.
  • All tests are passing.
  • New or changed API methods have been documented.
  • npm run format has been run

CHANGELOG

  • [FIXED] Makes Pusher's browser builds compatible with server-side rendering frameworks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pusher with encryption, window is not defined on Next.js
1 participant