♻️(frontend) isConnected when authenticated

WebSocketStatus.Connected does not mean
we are totally connected because authentication
can still be in progress and failed.
So we will use the event onAuthenticated to assert
that we are fully connected.
This commit is contained in:
Anthony LC
2025-12-14 21:33:13 +01:00
parent 4cf0e15406
commit bbf834fb6e
2 changed files with 19 additions and 3 deletions

View File

@@ -90,7 +90,7 @@ export const DocEditor = ({ doc }: DocEditorProps) => {
}
}, [isProviderReady, setIsSkeletonVisible]);
if (!isProviderReady) {
if (!isProviderReady || provider?.configuration.name !== doc.id) {
return <Loading />;
}

View File

@@ -52,13 +52,29 @@ export const useProviderStore = create<UseCollaborationStore>((set, get) => ({
}
},
onAuthenticationFailed() {
set({ isReady: true });
set({ isReady: true, isConnected: false });
},
onAuthenticated() {
set({ isReady: true, isConnected: true });
},
onStatus: ({ status }) => {
set((state) => {
const nextConnected = status === WebSocketStatus.Connected;
/**
* status === WebSocketStatus.Connected does not mean we are totally connected
* because authentication can still be in progress and failed
* So we only update isConnected when we loose the connection
*/
const connected =
status !== WebSocketStatus.Connected
? {
isConnected: false,
}
: undefined;
return {
isConnected: nextConnected,
...connected,
isReady: state.isReady || status === WebSocketStatus.Disconnected,
hasLostConnection:
state.isConnected && !nextConnected