Comments (4)
Thanks for the kind words. Believe it or not, but I've run into this very issue two days ago myself, and I have been meaning to investigate it more deeply. I'll try to take a look at it tomorrow, because you're right, and this replication is amazingly helpful! π―
from liveblocks.
Hey @dev-badace, I've opened a PR to fix this in #1463.
the ideal place to cleanup would be when machine exists the
@connecting.busy
. so right before the state is marked stale
Exactly. In this case, however, the @connection.busy
is implemented as a promise-based state (because it uses .onEnterAsync()
), which triggers a promise on enter, and will either (1) advance to @ok.connected
when it resolves, or (2) handle any failure case otherwise.
The way the machine is constructed guarantees that socket
is only observable/set when in the @ok.*
states. Other states simply don't know about a socket
instance by design. That why a cleanup function in the "on exit" handler for @connection.busy
is less useful and may falsely suggest that socket
is/can be set there.
So my fix is most in line with the ideal scenario: either the @connection.busy
promise returns a succesful socket instance and advances to @ok.*
sub states, or⦠an error happens and no traces are left behind. This fix takes care of the "leaving no traces behind" part, which was obviously missing here indeed.
Again, thanks for thinking along. Let me know what you think!
from liveblocks.
This fix is now published with v1.9.8.
from liveblocks.
I'm glad I was helpful. π
this is an interesting one. I'd like to also share a few solutions that came to my mind,
-
taking a third cleanup function for stale success cases however this still can lead to
>1
open websocket connections till the window it's cleared by the cleanup function -
a different variation of the above solution where the success case gets called with another argument boolean
isStale
, and checking for that, (hmm... i don't like this one).
the ideal place to cleanup would be when machine exists the @connecting.busy
. so right before the state is marked stale
return () => {
cancelled = true;
cleanup(this.current.context) //something like this, here we close the socket in context `tempSocket`
};
maybe additional piece of info in the context like tempSocket
that gets passed down to the cleanup via context.
from liveblocks.
Related Issues (20)
- history.batch() is not working at async callback function. HOT 4
- Unable to select any text when using liveblocks with cursors HOT 1
- In the multiplayer text editor with Tiptap, is it possible to specify the cursor colors from the frontend?
- Anomalous behavior occurs when repeating removing and inserting between LiveLists HOT 10
- Multiplayer text editor duplicating initial content
- The `@liveblocks/node` client crashes when secret key is invalid HOT 4
- Improve pagination API for `client.getRooms()` endpoint in `@liveblocks/node` HOT 5
- Problem to fetch data from Liveblocks API when not setting a schema HOT 3
- Delete thread server API
- useDeleteThread HOT 1
- Deleting a room should delete associated threads and comments for GDPR
- `TypeError: storage.get(...).get(...).set is not a function` with useMutation and nested live object HOT 2
- YJS Integration Does not Appear to Fire Awareness `update` Event HOT 1
- Yjs image upload > 500KB raises websocket error with code 1005 HOT 2
- Minor type error in Awareness.states
- React `useThreads` incorrect usage of `useSyncExternalStoreWithSelector` triggers infinite re-renders HOT 1
- Fix to the error: Type `LiveObject<Layer>` does not satisfy the constraint `Lson` HOT 2
- Ensure useSyncExternalStoreWithSelector usage are stable
- Support comments mention containing `@` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liveblocks.