y-crdt / yrb-actioncable

An ActionCable companion for Y.js clients.
https://y-crdt.github.io/yrb-actioncable/
MIT License
48 stars 5 forks source link

SSR fails with LocalStorage issue from BroadcastChannel #18

Closed eliias closed 1 year ago

eliias commented 1 year ago

When Node.js cannot be detected, but the app is server-side rendered, the following import statement fails due to initializing an instance of LocalStorage. We should introduce an SSR flag (mode) and re-implement the broadcastchannel with some lazy initialization for the LocalStorage, so that it will only be created when disableBc = false.

https://github.com/y-crdt/yrb-actioncable/blob/main/packages/yrb-actioncable/src/websocket-provider.ts#L2

import { publish, subscribe, unsubscribe } from 'lib0/broadcastchannel';
eliias commented 1 year ago

This can be fixed with a Vite "node-compat" plugin.