srcbookdev / srcbook

TypeScript-centric app development platform
https://srcbook.com
Apache License 2.0
2.6k stars 101 forks source link

Ensure socket messages are always sent for all npm installs #419

Closed 1egoman closed 1 month ago

1egoman commented 1 month ago

At a high level, this change should address the first two points in https://github.com/srcbookdev/srcbook/pull/418.

We had discussed previously the notion of whether making all npm installs client initiated would be an easy way to fix the first item. However, after getting more into this work, I opted to not do it this way. This was due to a mixture of not being able to come up with an elegant way to pass the state from the creation step to the actual apps interface to invoke the install, and that it seemed like it's likely folks could have multiple instances of a srcbook open and generally getting in the habit of broadcasting events so they all remain in sync no matter which instance caused an install to happen seemed like a good idea.

In more detail, this change:

  1. Ensures that for every npm install invocation made by the app, all relevant socket events are broadcasted to all connected clients on the given channel. Previously, some calls sent everything, some sent a few events, and some sent none. At least in my anecdotal observations, a lot of complex and hard to reason about situation were coming up due to the server and client's state not being synced.
  2. Adds a new message that gets sent when a npm install starts running. This means that all connected app instances will show a "loading" state, even if the npm install in question was initiated on the server or in another app instance.
  3. When a user joins a channel initially, send a message to them giving them an initial npm install status, so that if an install is in flight, the newly connected app can display this.