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:
@@ -45,7 +45,14 @@ export class WebSocketProvider {
|
|||||||
this.setStatus('connecting');
|
this.setStatus('connecting');
|
||||||
|
|
||||||
const fullUrl = `${this.url}/ws/collab/${encodeURIComponent(this.docName)}`;
|
const fullUrl = `${this.url}/ws/collab/${encodeURIComponent(this.docName)}`;
|
||||||
this.ws = new WebSocket(fullUrl);
|
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.binaryType = 'arraybuffer';
|
||||||
|
|
||||||
this.ws.onopen = () => {
|
this.ws.onopen = () => {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export interface UseYjsBindingResult {
|
|||||||
clearSelection: () => void;
|
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 {
|
export function useYjsBinding(opts: UseYjsBindingOptions): UseYjsBindingResult {
|
||||||
const { docName, wsUrl = DEFAULT_WS_URL, userId, userName, userColor, enabled = true } = opts;
|
const { docName, wsUrl = DEFAULT_WS_URL, userId, userName, userColor, enabled = true } = opts;
|
||||||
|
|||||||
Reference in New Issue
Block a user