fix: WebSocket wss:// same-origin URL + try/catch to prevent crash on HTTPS

- Change DEFAULT_WS_URL from ws://hostname:3001 to wss://window.location.host
- Wrap WebSocket constructor in try/catch to prevent React crash on connection error
- Fixes white page when opening a project (CADEditor crashed on insecure ws:// from HTTPS page)
This commit is contained in:
2026-06-26 17:58:06 +02:00
parent 1bcfaffdd4
commit 6d15a692af
2 changed files with 9 additions and 2 deletions
+7
View File
@@ -45,7 +45,14 @@ export class WebSocketProvider {
this.setStatus('connecting');
const fullUrl = `${this.url}/ws/collab/${encodeURIComponent(this.docName)}`;
try {
this.ws = new WebSocket(fullUrl);
} catch (err) {
console.warn('[WebSocketProvider] Failed to construct WebSocket:', err);
this.setStatus('error');
this.scheduleReconnect();
return;
}
this.ws.binaryType = 'arraybuffer';
this.ws.onopen = () => {
+1 -1
View File
@@ -41,7 +41,7 @@ export interface UseYjsBindingResult {
clearSelection: () => void;
}
const DEFAULT_WS_URL = `ws://${window.location.hostname}:3001`;
const DEFAULT_WS_URL = `wss://${window.location.host}`;
export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
const { docName, wsUrl = DEFAULT_WS_URL, userId, userName, userColor, enabled = true } = opts;