You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I understand (and support) that this library is aimed at the browser only, however, I am writing an app for which I do an initial run at build time, to generate HTML that can be displayed while client-side JS is being parsed and executed. I am trying to make sure that I'm not calling new Session at this point in time (because there's no browser environment yet), however, even just calling
Would it be possible to defer setting that onconnect listener to when it's actually needed, e.g. when a Session's constructor is being called? Or perhaps just to move RefreshMessageTypes to a separate module?
What is your setup? How can I reproduce the error you are facing?
I think this one is easy to solve - if it is really only the import. But I would like to check before asking you to go through the trouble of testing it for me.
Would it be possible to defer setting that onconnect listener to when it's actually needed
Well, I am not too happy with that idea - I think this might get messy because sessions keep overwriting stuff, file structure gets more complicated, etc. If it is just the enum import, no problem, I can extract that.
If you click that, you'll see the actual error self is not defined:
And note that I'm currently actually instantiating a Session object, but if you go one commit back, you can see that even just logging it is enough to trigger the error.
I do think that just extracting the enum would be sufficient 🤞
The fact that the lib automatically tries to register a SharedWorker is also a problem for Web apps, that load this lib (or another lib using it, like @pod-os/elements in my case) from CDN. Due to cross origin restrictions registering the SharedWorker fails.
In my understanding the lib should just provide the RefreshWorker.ts, but leave registration to the app. This means there are a few more lines of code to setup the app, but you gain the flexibility of using it without the worker or with a worker that actually is created on the same origin.
I am following a similar pattern with the service worker in PodOS. The worker setup is provided by a lib here:
@angelo-v , the lib does not automatically try to register a worker.
When you create a session, then the worker is automatically created for you.
What you are describing is a workaround for CORS issues when pulling the library from the CDN, thank you for raising this.
I could extend the SessionOptions to allow for an app-created SharedWorker to be passed to the session to solve that problem.
However, this is a different issue and not related to the side-effect of the import (of the session class) itself.
@Vinnl, thank you, I could reproduce the error. Extracting the enum seems to do the trick.
Activity
uvdsl commentedon Nov 4, 2025
What is your setup? How can I reproduce the error you are facing?
I think this one is easy to solve - if it is really only the import. But I would like to check before asking you to go through the trouble of testing it for me.
Well, I am not too happy with that idea - I think this might get messy because sessions keep overwriting stuff, file structure gets more complicated, etc. If it is just the enum import, no problem, I can extract that.
Reproduce error
Vinnl commentedon Nov 4, 2025
Oops sorry, bug reporting 101 🤦 Here's a minimal reproduction:
If you then open the given website (usually http://localhost:3000), then you'll see "1 issue" in the bottom left-hand corner:
If you click that, you'll see the actual error
self is not defined:And note that I'm currently actually instantiating a
Sessionobject, but if you go one commit back, you can see that even just logging it is enough to trigger the error.I do think that just extracting the enum would be sufficient 🤞
uvdsl commentedon Nov 4, 2025
Thanks, I'll check it out!
angelo-v commentedon Nov 5, 2025
The fact that the lib automatically tries to register a SharedWorker is also a problem for Web apps, that load this lib (or another lib using it, like @pod-os/elements in my case) from CDN. Due to cross origin restrictions registering the SharedWorker fails.
The problem is not the RefreshWorker.ts itself, but the fact, that this script is registered as a worker here.
In my understanding the lib should just provide the RefreshWorker.ts, but leave registration to the app. This means there are a few more lines of code to setup the app, but you gain the flexibility of using it without the worker or with a worker that actually is created on the same origin.
I am following a similar pattern with the service worker in PodOS. The worker setup is provided by a lib here:
https://github.com/pod-os/PodOS/blob/main/service-worker/src/setupServiceWorker.ts
But is actually called in a thin layer script on same origin as the actual app:
https://github.com/pod-os/PodOS/blob/main/apps/service-worker.js
uvdsl commentedon Nov 5, 2025
@angelo-v , the lib does not automatically try to register a worker.
When you create a session, then the worker is automatically created for you.
What you are describing is a workaround for CORS issues when pulling the library from the CDN, thank you for raising this.
I could extend the SessionOptions to allow for an app-created SharedWorker to be passed to the session to solve that problem.
However, this is a different issue and not related to the side-effect of the import (of the session class) itself.
@Vinnl, thank you, I could reproduce the error. Extracting the enum seems to do the trick.