-
Notifications
You must be signed in to change notification settings - Fork 96
feat(zero): offline #4652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(zero): offline #4652
Conversation
@0xcadams is attempting to deploy a commit to the Rocicorp Team on Vercel. A member of the Team first needs to authorize it. |
|
||
const raceResult = await promiseRace([sleep(5000), result.server]); | ||
if (raceResult === 0) { | ||
// TODO show toast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this to be a toast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should rely on a new global onError
handler that Matt is constantly wanting to add. It is half-implemented in the codebase right now, but we got distracted by API design questions and never finished it.
I don't want every mutator to have to do this kind of error handling manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense - agreed it would be much better to have this in onError
. So I can add this toast later and only have this PR include online indicator, once the onError handler lands.
I'm confused - we already have |
@alexhking can you design an online indicator for zbugs? Note that people will probably copy whatever we do into their apps. Here are my product thoughts:
|
Yeah I can do that - it just means managing that state in two places and adds a new Context. Will change. |
I am missing something.... it seems trivial to wrap a hook around the existing feature. I don't get why any change is needed in zero.ts. |
Oooh it is because there can be many hooks, but there can only be one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like this.
|
||
const raceResult = await promiseRace([sleep(5000), result.server]); | ||
if (raceResult === 0) { | ||
// TODO show toast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should rely on a new global onError
handler that Matt is constantly wanting to add. It is half-implemented in the codebase right now, but we got distracted by API design questions and never finished it.
I don't want every mutator to have to do this kind of error handling manually.
@@ -0,0 +1,38 @@ | |||
export class Subscribable< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also @arv just confirming there's nothing like this already in Replicache so we don't duplicate code?
* @param listener - The listener to subscribe to. | ||
* @returns A function to unsubscribe the listener. | ||
*/ | ||
addOnlineChangeListener = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about onOnline
and then we deprecate onOnlineChange
.
); | ||
} | ||
|
||
this.#onOnlineChange = onOnlineChange; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change but it is so simple to update I am supportive.
@alexhking I changed the design based on the above comments. Open to feedback. See the description for the current design. I can add tooltip, etc. |
@aboodman - should we just merge rather than having this open/blocked and fix forward? Seems annoying and unproductive to have to have PRs open for such a long time (having to rebase and resolve merge conflicts to revisit). |
Hey Chase, for some reason I didn't get notified when you sent this last week. Checking out now and will give feedback. |
Ok, after reviewing I have several questions and comments:
I would like to take a stab at redesigning this just a bit at least visually. |
Typically we would but just because Chase was new to the team I suggested he block on reviews and start conservatively. Will re-evaluate. |
} | ||
return login.loginState?.encoded; | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this change is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not - an artifact of other changes made and then kept because it added type safety. Can remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does it improve about type safety? Currently for me I do not see any type errors in my env w/o this.
The reason I'm asking is because zbugs is a testbed for how we expect Zero to be used and I wasn't expecting this to be required of users.
/** | ||
* `onOnlineChange` is called when the Zero instance's online status changes. | ||
* | ||
* @deprecated Use `onOnline` on the Zero instance instead. e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nuts. @grgbkr had gone to a lot of trouble to pass in all the configuration to Zero
. But I think didn't consider this problem/use-case. So maybe passing in all configuration cannot work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can support both here. The adding/removal of listeners doesn't need to be all up-front. And this doesn't need to be deprecated.
Or, if it's better, we can move this all to the React/Solid layers. And continue to use onOnlineChange
and track the online state with React Context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be very convoluted to track the listeners state in the React/Solid layers. I'm ok with this change.
The other to event listener type configs we currently have are onUpdateNeeded
and onClientStateNotFound
. Possibly these should move on to the Zero instance as well, and our general pattern would be event listeners on the Zero instance. I think these are unlikely to need multiple listeners like onOnline might, but it may just be more ergonomic to have them on Zero given React hooks. I think it would be good to build a UI for onUpdateNeeded
to figure out what is most ergonomic.
On these - I am completely open to the design you want to go with. I am still getting used to what design styles the team likes, so I did not put a lot of time into the design (this was a very loose copy of how Linear does it). Please let me know if you want me to add tooltip, etc. |
I don't think so... is there some reason to do @0xcadams ? Prefer to keep login state looking the same while offline.
Please! Sounds great! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo type question.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I have removed all changes to zbugs so we can update the styling/display of offline in a future PR. |
I think it is fine to land the zbugs changes and let Alex style them
separately. It wasn’t bad enough to delay. And having the usage of the api
somewhere is great for dogfooding purposes.
a (phone)
…On Wed, Jul 30, 2025 at 7:54 AM Chase Adams ***@***.***> wrote:
*0xcadams* left a comment (rocicorp/mono#4652)
<#4652 (comment)>
I have removed all changes to zbugs so we can update the styling/display
of offline in a future PR.
—
Reply to this email directly, view it on GitHub
<#4652 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAATUBARDQBAAZTJHXZM6EL3LEBDXAVCNFSM6AAAAACB3KORL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCMZXGMYTQMRQHE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This reverts commit dd11919.
Sounds good - added back and merging and will note to follow up w/ @alexhking to get better styling here. |
There was a usability issue with the online status with Zero. React doesn't rerender when Zero's online property updates. This proposes an API,
onOnline
, to make it easier to listen for updates to this. And an accompanying hook in React/SolidJS,useZeroOnline
.