dmonad / lib0

Monorepo of isomorphic utility functions
MIT License
347 stars 62 forks source link

Don’t register storage event listener in Node.js environments #26

Closed hanspagel closed 3 years ago

hanspagel commented 3 years ago

This PR

  1. Checks if it’s running in a browser context.
  2. Only then registers the storage event listener in the LocalStoragePolyfill.

Merging this PR would make y-websocket run in Node.js environments, see https://github.com/yjs/y-websocket/issues/51 https://github.com/yjs/y-websocket/issues/55

Alternative solutions

  1. It doesn’t make sense to use the LocalStoragePolyfill in Node.js environments at all. A check to load the Polyfill only in a browser context would probably work too.
  2. Add for example node-localstorage to add support for localstorage to Node.js.

Let me know if you I can do anything to improve the PR. 💖

dmonad commented 3 years ago

Hey @hanspagel ,

Thanks for the PR! I want to leave the option open to implement an actual storage polyfill for nodejs. So I went with a slightly different approach and added a global event listener storage.onChange(event => ..) that should be used instead. Hope this works for you. I closed the related issues in y-websocket already. Let me know if there are still issues.

The issue is fixed in lib0@v0.2.41.